Any logging you do is going to be slower than doing no logging. Logging isn't about performance, it's about reliability and recovery. The best logging framework is the one you use religiously, the worst one is the one you don't use.
We use log4net in our applications, no complaints and have never looked back. Are there things I'd like to tweak? Sure. But we're not in the logging business, we write applications for clients, so we need a reliable* logging system, and log4net fits.
Having said that, we do wrap our debug logs in a check for debug logging. And in core places only we went beyond the typical if (log.isDebugEnabled)
check and added in our own static variable check on each if statement. At the top of modules where we really care about performance (mostly parts of our ORM or other infrastructure pieces) we have
#region Log4Net
const string c_EnableDebugLogging = "com.techsoftinc.BusinessObjectsCore.EnableDebugLogging";
static readonly bool _EnableDebugLogging = Convert.ToBoolean(ConfigurationManager.AppSettings[c_EnableDebugLogging] ?? "false");
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//Do we support ultrafast logging? See What is REALLY the FASTEST way of (not) logging? in http://logging.apache.org/log4net/release/faq.html
static bool debugLogging
{
get { return _EnableDebugLogging && log.IsDebugEnabled; }
}
#endregion
and then when we want to debug we have (for example)
if (debugLogging)
log.DebugFormat("Executing sql: {0}", sql);
If _EnableDebugLogging is false then the JIT will collapse the debugLogging function to a false
and then remove the entire if (debugLogging)
statement since it can never be true. The JIT is literally dropping our debug logging on the floor if we don't need it.
*reliable == works well in all situations we've encountered. Reliable does not mean truely reliable in the computer science sense of the term.