Created
January 29, 2020 15:12
-
-
Save SamKr/44900e139c96e642b58f1108f3107108 to your computer and use it in GitHub Desktop.
SeriLog logger
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
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.WriteTo.Console() | |
.WriteTo.File("logfile.log", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Information) | |
.WriteTo.CoderrSeriLogSink() | |
.CreateLogger(); | |
public class CoderrSeriLogSink : ILogEventSink | |
{ | |
private readonly IFormatProvider _formatProvider; | |
public CoderrSeriLogSink(IFormatProvider formatProvider) | |
{ | |
_formatProvider = formatProvider; | |
} | |
public void Emit(LogEvent logEvent) | |
{ | |
if (logEvent.Exception == null) return; | |
Err.Report(logEvent.Exception, logEvent.RenderMessage(_formatProvider)); | |
} | |
} | |
public static class HdSinkExtensions | |
{ | |
public static LoggerConfiguration CoderrSeriLogSink(this LoggerSinkConfiguration loggerConfiguration, IFormatProvider formatProvider = null) | |
{ | |
return loggerConfiguration.Sink(new CoderrSeriLogSink(formatProvider)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment