Created
November 29, 2017 20:53
-
-
Save ericnewton76/8b988cdaa2757903c00b31a13fd2074a to your computer and use it in GitHub Desktop.
NLog contribution logger extension for logging an action.
This file contains hidden or 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 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