EDIT: While similar, this is not the same as the questions about using an NLog wrapper. Extension methods add another level of indirection which makes even a proper wrapper report the wrong callsite
I currently use a logging wrapper around NLog, and I use the trick they show in the example in their source for getting accurate callsite info. For a new project I started, I wanted to create a simpler class, so I just implemented something like the following interface:
public interface ILogger
{
void Log( LogEntry entry );
}
And then I created an extension method class like:
public static class LoggerExtensions
{
public static void Debug( this ILogger logger, string format, params object[] args)
{
logger.Log( new LogEntry( LogLevel.Debug, format, args ) );
}
...
}
The problem is that NLog then shows the callsite as the extension method instead of the caller of the extension method. I did a little searching around but couldn't find anything about NLog and extension methods.
Is it possible to fix the callsite information in this case? Or is the only way to include the Debug,Info, etc functions in the interface itself?