Created
August 1, 2018 12:19
-
-
Save MovGP0/93cbf317290d914fafaed0a8cbe5a2df to your computer and use it in GitHub Desktop.
Serilog Extensions
This file contains 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 Here(this ILogger logger, | |
[CallerMemberName] string memberName = "", | |
[CallerFilePath] string sourceFilePath = "", | |
[CallerLineNumber] int sourceLineNumber = 0) { | |
return logger | |
.ForContext("MemberName", memberName) | |
.ForContext("FilePath", sourceFilePath) | |
.ForContext("LineNumber", sourceLineNumber); | |
} | |
} |
This file contains 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
var outputTemplate = "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}in method {MemberName} at {FilePath}:{LineNumber}{NewLine}{Exception}{NewLine}"; | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Warning() | |
.Enrich.FromLogContext() | |
.WriteTo.RollingFile("log/{Date}.log", outputTemplate, LogEventLevel.Warning) | |
.WriteTo.Console(LogEventLevel.Warning, outputTemplate, theme: AnsiConsoleTheme.Literate) | |
.CreateLogger(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment