Skip to content

Instantly share code, notes, and snippets.

@ericnewton76
Created November 29, 2017 20:53
Show Gist options
  • Save ericnewton76/8b988cdaa2757903c00b31a13fd2074a to your computer and use it in GitHub Desktop.
Save ericnewton76/8b988cdaa2757903c00b31a13fd2074a to your computer and use it in GitHub Desktop.
NLog contribution logger extension for logging an action.
public static class NLogLoggerExtensions
{
public static void LogAction(this NLog.ILogger Log, Action action, string startingVerb, string completedVerb, string format, params object[] args)
{
try
{
if(Log.IsDebugEnabled)
{
Log.Debug(format.Replace("[verb]", startingVerb), args);
}
action();
Log.Info(format.Replace("[verb]", completedVerb), args);
}
catch(Exception ex)
{
Log.Error(ex, "XXX failed.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment