This project is read-only.

Explore the impact of SLF on nlog / log4net stacktraces


Both NLog and log4net have formatters that output information relating to the call-stack. Currently SLF will obscure this.
What can we do?
The only solution I can thin of, which is a bit nasty, is to create our own builds of NLog and log4net that skip stack frames.


wageoghe wrote Sep 10, 2010 at 7:31 PM

I have added a comment in the "callsite is lost through the NLogFacade" discussion thread about how to fix this problem for log4net. You can look there for more info, or I will also include some sample code here:

/// <summary>
/// Sends the message to the underlying log4net system.
/// </summary>
/// <param name="logLevel">the level of this log event.</param>
/// <param name="message">the message to log</param>
/// <param name="exception">the exception to log (may be null)</param>
protected override void WriteInternal(LogLevel logLevel, object message, Exception exception)
Level level = GetLevel(logLevel);
_logger.Log(declaringType, level, message, exception);

By using the log4net logger's "Log" method and passing the type of the wrapping logger, log4net knows which DeclaringType in the call stack is the entry point for the logging call. One step up from that should be in the actual user code.

wrote Feb 14, 2013 at 3:49 AM