Created
February 19, 2017 02:33
-
-
Save wgross/bea2209ee1395b60df2e962e93a041a4 to your computer and use it in GitHub Desktop.
Adding Callerinfo to Serilog Context
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 LoggerExtensions | |
{ | |
public static ILogger WithCallerInfo(this ILogger logger, | |
[CallerMemberName]string callerMemberName = null, | |
[CallerFilePath]string callerFilePath = null, | |
[CallerLineNumber]int callerLineNumber = 0) | |
{ | |
return logger | |
// substituting 'Caller' with 'Source' because 'ForContext<T>()' adds property 'SourceContext' | |
.ForContext("SourceMemberName", callerMemberName) | |
.ForContext("SourceFilePath", callerFilePath) | |
.ForContext("SourceLineNumber", callerLineNumber); | |
} | |
} | |
// see also: https://gist.github.com/cbdabner/b2c921a3a6da05cdb946 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment