Skip to content

Instantly share code, notes, and snippets.

@nblumhardt
Created February 10, 2014 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nblumhardt/8914175 to your computer and use it in GitHub Desktop.
Save nblumhardt/8914175 to your computer and use it in GitHub Desktop.
An alternative to stack walking to add caller names to Serilog events
public static class LoggerExtensions
{
public static ILogger ForHere(
this ILogger logger,
[CallerFilePath] string sourceFile = null,
[CallerLineNumber] int sourceLine = 0)
{
return logger
.ForContext("SourceFile", sourceFile)
.ForContext("SourceLine", sourceLine);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment