Like many other libraries for .NET, Serilog provides diagnostic logging to files, the console, and elsewhere. It is easy to set up, has a clean API, and is portable between recent .NET platforms.
Unlike other logging libraries, Serilog is built with powerful structured event data in mind.
Serilog message templates are a simple DSL extending .NET format strings. Parameters can be named, and their values are serialized as properties on the event for incredible searching and sorting flexibility:
This example records two properties, Position
and
Elapsed
along with the log event. The properties
captured in the example, in JSON format, would appear like:
The @
operator in front of Position
tells Serilog to serialize the object passed in,
rather than convert it using ToString()
.
The :000
segment following Elapsed
is a
standard .NET format string
that affects how the property is rendered. The console
sink included with Serilog will display the above message as:
You'll find heaps of information and advice about using Serilog on the project site: