Skip to content

Instantly share code, notes, and snippets.

@maftieu
Created November 25, 2015 09:42
Show Gist options
  • Save maftieu/02aa89013c9258de9722 to your computer and use it in GitHub Desktop.
Save maftieu/02aa89013c9258de9722 to your computer and use it in GitHub Desktop.
NLog extensions
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