private static NLogLevel ConvertTo(LogLevel logLevel) { switch (logLevel) { case LogLevel.Debug: return NLogLevel.Debug; case LogLevel.Error: return NLogLevel.Error; case LogLevel.Fatal: return NLogLevel.Fatal; case LogLevel.Informational: return NLogLevel.Info; case LogLevel.Trace: return NLogLevel.Trace; case LogLevel.Warning: return NLogLevel.Warn; } Ensure.EnumValueIsDefined(() => logLevel); return NLogLevel.Trace; }
public override void Log(LogLevel logLevel, Exception exception, string message, params object[] args) { var nlogLevel = ConvertTo(logLevel); if ((exception == null && message.IsNullOrWhiteSpace()) || !IsLoggable(logLevel)) return; var writer = new StringWriter(); if (message.IsNotNullOrWhiteSpace()) writer.WriteLine(message, args); if (exception != null) { var formatter = ExceptionFormatterFactory.Get(exception.GetType()); formatter.Write(exception, writer); } var logEventInfo = LogEventInfo.Create(nlogLevel, _logger.Name, writer.ToString(), exception); Log(logEventInfo); }
public override bool IsLoggable(LogLevel logLevel) { return _logger.IsEnabled(ConvertTo(logLevel)); }