Created
November 25, 2015 09:42
-
-
Save maftieu/02aa89013c9258de9722 to your computer and use it in GitHub Desktop.
NLog extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NLogExtensions | |
{ | |
public static void WarnIf(this NLog.ILogger @this, bool condition, string message) | |
{ | |
if (condition && @this.IsWarnEnabled) | |
{ | |
@this.Warn(message); | |
} | |
} | |
/* | |
// to be improved | |
public static TimedLoggerClass TimedLogger(this NLog.ILogger @this, NLog.LogLevel level, string format) | |
{ | |
return new TimedLoggerClass(@this, level, format); | |
} | |
public class TimedLoggerClass : IDisposable | |
{ | |
public NLog.ILogger Logger { get; private set; } | |
public NLog.LogLevel Level { get; private set; } | |
public string Format { get; private set; } | |
private int ticksStart; | |
internal TimedLoggerClass(NLog.ILogger logger, NLog.LogLevel level, string format) | |
{ | |
this.Logger = logger; | |
this.Level = level; | |
this.Format = format; | |
this.ticksStart = Environment.TickCount; | |
} | |
#region IDisposable Members | |
public void Dispose() | |
{ | |
int tickEnd = Environment.TickCount; | |
var ts = TimeSpan.FromMilliseconds(tickEnd - ticksStart); | |
Logger.Log(Level, string.Format(Format, ts)); | |
} | |
#endregion | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment