Using .Net core default logger to log system events in production environment quite often can complicate things when attempting to aggregate and analise logs from multiple services via log analysers such as Sumo Logic
Default Logger console writes are easy to read but basically become useless when thousands of messages are being collected into centralised analysis dashboard.
Serilog library on the other hand allows for structured event logging.
Also, with the help of various extensions and segregation of settings for dev and prod environment it possible to output coloured logs for ease of reading in IDE and de-serialise log message with JSON for improved data analysis.
Setting up Serilog
I use following nuget packages
- Serilog (main package)
- Serilog.AspNetCore (NetCore Adapter)
- Serilog.Sinks.Console (sink that writes log events to the console)
- Serilog.Settings.Configuration (Extension adapter for using appsettings.json
some code omitted for brevity
It is safe to remove logging section from all appsettings.%ENV%.json files, Serilog has its separate overrides
Sample use in ClazzService