Serilog is a set of libraries used to log program usage.
For C Sharp ASP.Net Core, it integrates into your ILogger.
The idea is you hook it into your startup program. And from that point it’s working. Then you sprinkle your code (especially error handlers) with logger statements.
It’s kind of an industry standard. At least its really realy popular.
there are
Log Levels
| Level | Usage |
|---|---|
| Verbose | Verbose is the noisiest level, rarely (if ever) enabled for a production app. } |
| Debug | Debug is used for internal system events that are not necessarily observable from the outside, but useful when determining how something happened. |
| Information | Information events describe things happening in the system that correspond to its responsibilities and functions. |
| Warning | When service is degraded, endangered, or maybe behaving outside its expected parameters, Warning-level events are used. |
| Error | When functionality is unavailable or expectations are broken, an Error event is used. |
| Fatal | The most critical level, Fatal events demand immediate attention. |
Sinks
Sinks are drivers that let you route logging to where you want it to go. For example to a console, a text file, an Elastic server.
Popular Sinks include
- Console - sends logging to the system console. Built into serilog.
- File - sends logging to a file. Built into serilog.
- Elastic - sends logging information to an elastic server.
Structured logging
Out of the box serilog sends output as an text stream - one row per message. But it is possible to send it out in a json format. Which becomes useful for the advanced logging system (Elastic, etc)
Enrichers
If you enable structured logging, then you can make use of enrichers. These are add-in’s which add more data to the logging. Mukesh describes Environment, Process, and Tread enrichers.
Request Logging
Request logging logs HTTP requests.
My first experiences with Serilog, I added in an APM add-in which I think did the same thing. It’s possible the APM Add-in was to move those requests into a different channel in the serilog server. It’s also possible that Serilog now does this built in.
References
- https://codewithmukesh.com/blog/structured-logging-with-serilog-in-aspnet-core/ - has a good introduction to serilog. Has a good best practices. Introduces SEQ
- https://github.com/serilog/serilog/wiki/Formatting-Output - describes how to format outputs, something not yet added to my code.