Skip to content

Instantly share code, notes, and snippets.

@SamKr
Created January 29, 2020 15:12
Show Gist options
  • Save SamKr/44900e139c96e642b58f1108f3107108 to your computer and use it in GitHub Desktop.
Save SamKr/44900e139c96e642b58f1108f3107108 to your computer and use it in GitHub Desktop.
SeriLog logger
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