Hi,
A have a static logger wrapper that uses a custom ILogger interface that I use to implement a NLog writer, like this:
public static class Logger
{
private static ILogger currentLogger;
/// <summary>
/// Gets the current logger.
/// </summary>
public static ILogger CurrentLogger
{
get
{
if (currentLogger == null)
{
currentLogger = new NLogLogger();
}
return currentLogger;
}
set
{
currentLogger = value;
}
}
}
My NLogLogger implementation is like this:
public class NLogLogger : ILogger
{
private static NLog.Logger logger = null;
public void Log(LogTypeEnum logType, Exception ex, string message, params object[] args)
{
if (logger == null)
{
logger = NLog.LogManager.GetCurrentClassLogger();
}
var msg = Logger.FormatMessage(message, args);
var logLevel = LogLevel.Info;
switch (logType)
{
case LogTypeEnum.Warning:
logLevel = LogLevel.Warn;
break;
case LogTypeEnum.Error:
logLevel = LogLevel.Error;
break;
case LogTypeEnum.Debug:
logLevel = LogLevel.Debug;
break;
}
var formatProvider = System.Globalization.CultureInfo.InvariantCulture;
var logEvent = new LogEventInfo(logLevel, logger.Name, formatProvider, msg, args, ex);
// Para que o callsite não tenha o wrapper
logger.Log(typeof(NLogLogger), logEvent);
}
}
My problem is that when I use ${callsite} it always return the static wrapper method: "Logging.Logger.Log"
If I put the static class type in the NLog "logger.Log" call the callsite returns the NLogLogger method.
Is there any way to avoid this and return the caller of "Logger.Log"?
PS - With Log4Net I can do that because they have a parameter: callerStackBoundaryDeclaringType and if I set the Logger type it works well.
Thanks