Why Serilog?
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.
Text formatting with a twist
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:
var
position =
new
{ Latitude =
25
, Longitude =
134
};
var
elapsedMs =
34
;
log.Information(
"Processed
{@Position}
in
{Elapsed:000}
ms."
, position, elapsedMs);
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:
{"Position": {"Latitude": 25, "Longitude": 134}, "Elapsed": 34}
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:
09:14:22 [Information] Processed { Latitude: 25, Longitude: 134 } in 034 ms.
Documentation
You'll find heaps of information and advice about using Serilog on
the project site:
Installation
Configuration basics
Writing log events
Structured data
Provided sinks
Debugging and diagnostics
Resources
GitHub project
serilog
tag on Stack Overflow
Blog posts at nblumhardt.com
Packages on NuGet
Serilog integration for ASP.NET Core 2+
Gitter chat
Serilog is open source software under the
Apache 2.0
license, copyright © and maintained by its
contributors
.