Last active
May 17, 2018 15:25
-
-
Save gcollic/0ce7c775efe125555c6cc6e796f36844 to your computer and use it in GitHub Desktop.
Trying Serilog in LinqPad ( gist version of https://twitter.com/adamchester/status/726965534693056513 )
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
void Main() | |
{ | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Warning() | |
.Enrich.FromLogContext() | |
.Enrich.WithProperty("url", "http://serilog.net/") | |
.WriteTo.Sink(new LinqpadDumpSink()) | |
.CreateLogger(); | |
Log.Warning( | |
"Processing inside {@test}, something weird happened", | |
typeof(Int32).GetMethod("GetTypeCode")); | |
} | |
class LinqpadDumpSink : Serilog.Core.ILogEventSink | |
{ | |
public void Emit(LogEvent @event) | |
{ | |
@event.RenderMessage().Dump(); | |
new { | |
Basiclnfo = new | |
{ | |
@event.Level, | |
@event.MessageTemplate.Text | |
}, | |
@event.Properties, | |
@event.Exception, | |
}.Dump(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool. Very helpful. Thanks for sharing.