Serilog 4.3.0

Serilog Build status NuGet Version NuGet Downloads Stack Overflow

Serilog is a diagnostic logging library for .NET applications. It is easy to set up, has a clean API, and runs on all recent .NET platforms. While it's useful even in the simplest applications, Serilog's support for structured logging shines when instrumenting complex, distributed, and asynchronous applications and systems.

Serilog

Like many other libraries for .NET, Serilog provides diagnostic logging to files, the console, and many other outputs.

using var log = new LoggerConfiguration()
    .WriteTo.Console()
    .WriteTo.File("log.txt")
    .CreateLogger();

log.Information("Hello, Serilog!");

Unlike other logging libraries, Serilog is built from the ground up to record structured event data.

var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;

log.Information("Processed {@Position} in {Elapsed} ms", position, elapsedMs);

Serilog uses message templates, a simple DSL that extends .NET format strings with named as well as positional parameters. Instead of formatting events immediately into text, Serilog captures the values associated with each named parameter.

The example above records two properties, Position and Elapsed, in the log event. The @ operator in front of Position tells Serilog to serialize the object passed in, rather than convert it using ToString(). Serilog's deep and rich support for structured event data opens up a huge range of diagnostic possibilities not available when using traditional loggers.

Rendered into JSON format for example, these properties appear alongside the timestamp, level, and message like:

{"Position": {"Latitude": 25, "Longitude": 134}, "Elapsed": 34}

Back-ends that are capable of recording structured event data make log searches and analysis possible without log parsing or regular expressions.

Supporting structured data doesn't mean giving up text: when Serilog writes events to files or the console, the template and properties are rendered into friendly human-readable text just like a traditional logging library would produce:

09:14:22 [INF] Processed {"Latitude": 25, "Longitude": 134} in 34 ms.

Upgrading from an earlier Serilog version? Find release notes here.

Features

  • Community-backed and actively developed
  • Format-based logging API with familiar levels like Debug, Information, Warning, Error, and so-on
  • Discoverable C# configuration syntax and optional XML or JSON configuration support
  • Efficient when enabled, extremely low overhead when a logging level is switched off
  • Best-in-class .NET Core support, including rich integration with ASP.NET Core
  • Support for a comprehensive range of sinks, including files, the console, on-premises and cloud-based log servers, databases, and message queues
  • Sophisticated enrichment of log events with contextual information, including scoped (LogContext) properties, thread and process identifiers, and domain-specific correlation ids such as HttpRequestId
  • Zero-shared-state Logger objects, with an optional global static Log class
  • Format-agnostic logging pipeline that can emit events in plain text, JSON, in-memory LogEvent objects (including Rx pipelines) and other formats

Getting started

Serilog is installed from NuGet. To view log events, one or more sinks need to be installed as well, here we'll use the pretty-printing console sink, and a rolling file set:

dotnet add package Serilog
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.File

The simplest way to set up Serilog is using the static Log class. A LoggerConfiguration is used to create and assign the default logger, normally in Program.cs:

using Serilog;

Log.Logger = new LoggerConfiguration()
    .WriteTo.Console()
    .WriteTo.File("log.txt",
        rollingInterval: RollingInterval.Day,
        rollOnFileSizeLimit: true)
    .CreateLogger();

try
{
    // Your program here...
    const string name = "Serilog";
    Log.Information("Hello, {Name}!", name);
    throw new InvalidOperationException("Oops...");
}
catch (Exception ex)
{
    Log.Error(ex, "Unhandled exception");
}
finally
{
    await Log.CloseAndFlushAsync(); // ensure all logs written before app exits
}

Find more, including a runnable example application, under the Getting Started topic in the documentation.

Getting help

To learn more about Serilog, check out the documentation - you'll find information there on the most common scenarios. If Serilog isn't working the way you expect, you may find the troubleshooting guide useful.

Serilog has an active and helpful community who are happy to help point you in the right direction or work through any issues you might encounter. You can get in touch via:

We welcome reproducible bug reports and detailed feature requests through our GitHub issue tracker; note the other resource are much better for quick questions or seeking usage help.

Contributing

Would you like to help make Serilog even better? We keep a list of issues that are approachable for newcomers under the up-for-grabs label (accessible only when logged into GitHub). Before starting work on a pull request, we suggest commenting on, or raising, an issue on the issue tracker so that we can help and coordinate efforts. For more details check out our contributing guide.

When contributing please keep in mind our Code of Conduct.

Serilog is copyright © Serilog Contributors - Provided under the Apache License, Version 2.0. Needle and thread logo a derivative of work by Kenneth Appiah.

Showing the top 20 packages that depend on Serilog.

Packages Downloads
Serilog.AspNetCore
Serilog support for ASP.NET Core logging
20
Serilog.Sinks.Console
The console sink for Serilog.
20
Serilog.Sinks.Console
A Serilog sink that writes log events to the console/terminal.
20
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
20
Serilog.Sinks.Console
The console sink for Serilog.
19
Serilog.Extensions.Hosting
Serilog support for .NET Core logging in hosted services
19
Serilog.AspNetCore
Serilog support for ASP.NET Core logging
19
Serilog.Sinks.Console
A Serilog sink that writes log events to the console/terminal.
19
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
19

.NET Framework 4.6.2

.NET Standard 2.0

.NET 9.0

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET 6.0

  • No dependencies.

.NET Framework 4.7.1

Version Downloads Last updated
4.3.0 15 08/10/2025
4.2.0 16 08/10/2025
4.1.0 16 08/10/2025
4.1.0-dev-02311 15 07/10/2025
4.0.2 14 08/10/2025
4.0.1 14 08/10/2025
4.0.0 14 08/10/2025
3.1.1 15 08/10/2025
3.1.0 15 08/10/2025
3.1.0-dev-02083 14 07/09/2025
3.0.1 14 08/10/2025
3.0.0 14 08/10/2025
3.0.0-dev-02018 18 07/12/2025
3.0.0-dev-01998 13 07/12/2025
3.0.0-dev-01899 16 07/08/2025
3.0.0-dev-01885 11 07/11/2025
3.0.0-dev-01839 12 07/11/2025
3.0.0-dev-01838 12 07/11/2025
3.0.0-dev-01787 12 07/12/2025
2.12.1-dev-01634 13 07/12/2025
2.12.1-dev-01620 13 07/13/2025
2.12.0 15 08/10/2025
2.12.0-dev-01551 14 07/08/2025
2.12.0-dev-01543 13 07/12/2025
2.12.0-dev-01511 14 07/11/2025
2.12.0-dev-01479 13 07/11/2025
2.12.0-dev-01458 13 07/10/2025
2.12.0-dev-01447 13 07/13/2025
2.12.0-dev-01435 13 07/10/2025
2.11.0 15 08/10/2025
2.10.1-dev-01248 12 07/10/2025
2.10.0 15 08/10/2025
2.10.0-dev-01187 14 07/12/2025
2.9.0 14 08/10/2025
2.8.0 13 08/10/2025
2.7.1 17 08/10/2025
2.6.0 16 08/10/2025
2.5.0 17 08/10/2025
2.4.0 14 08/10/2025
2.3.0 15 08/10/2025
2.2.1 13 08/10/2025
2.2.0 14 08/10/2025
2.1.0 15 08/10/2025
2.0.0 16 08/10/2025
2.0.0-rc-640 19 08/10/2025
2.0.0-rc-634 16 08/10/2025
2.0.0-rc-633 14 08/10/2025
2.0.0-rc-628 17 08/10/2025
2.0.0-rc-622 13 08/10/2025
2.0.0-rc-621 17 08/10/2025
2.0.0-rc-606 17 08/10/2025
2.0.0-rc-602 16 08/10/2025
2.0.0-rc-600 16 08/10/2025
2.0.0-rc-577 15 08/10/2025
2.0.0-rc-573 17 08/10/2025
2.0.0-rc-563 15 08/10/2025
2.0.0-rc-556 14 08/10/2025
1.5.14 15 08/10/2025
1.5.13 19 08/10/2025
1.5.12 17 08/10/2025
1.5.11 19 08/10/2025
1.5.10 14 08/10/2025
1.5.9 13 08/10/2025
1.5.8 14 08/10/2025
1.5.7 18 08/10/2025
1.5.6 14 08/10/2025
1.5.5 15 08/10/2025
1.5.1 13 08/10/2025
1.4.214 13 08/10/2025
1.4.204 14 08/10/2025
1.4.196 13 08/10/2025
1.4.182 14 08/10/2025
1.4.168 14 08/10/2025
1.4.155 14 08/10/2025
1.4.154 15 08/10/2025
1.4.152 15 08/10/2025
1.4.139 14 08/10/2025
1.4.128 13 08/10/2025
1.4.126 12 08/10/2025
1.4.118 14 08/10/2025
1.4.113 14 08/10/2025
1.4.102 17 08/10/2025
1.4.99 14 08/10/2025
1.4.97 14 08/10/2025
1.4.95 19 08/10/2025
1.4.76 17 08/10/2025
1.4.75 17 08/10/2025
1.4.39 16 08/10/2025
1.4.34 15 08/10/2025
1.4.28 15 08/10/2025
1.4.27 15 08/10/2025
1.4.23 17 08/10/2025
1.4.22 15 08/10/2025
1.4.21 15 08/10/2025
1.4.18 15 08/10/2025
1.4.17 14 08/10/2025
1.4.16 16 08/10/2025
1.4.15 16 08/10/2025
1.4.14 16 08/10/2025
1.4.13 16 08/10/2025
1.4.12 15 08/10/2025
1.4.11 13 08/10/2025
1.4.10 14 08/10/2025
1.4.9 15 08/10/2025
1.4.8 15 08/10/2025
1.4.7 15 08/10/2025
1.4.6 13 08/10/2025
1.4.5 15 08/10/2025
1.4.4 13 08/10/2025
1.4.3 14 08/10/2025
1.4.2 14 08/10/2025
1.4.1 15 08/10/2025
1.3.43 13 08/10/2025
1.3.42 13 08/10/2025
1.3.41 13 08/10/2025
1.3.40 15 08/10/2025
1.3.39 12 08/10/2025
1.3.38 16 08/10/2025
1.3.37 13 08/10/2025
1.3.36 14 08/10/2025
1.3.35 18 08/10/2025
1.3.34 17 08/10/2025
1.3.33 16 08/10/2025
1.3.30 13 08/10/2025
1.3.29 14 08/10/2025
1.3.28 17 08/10/2025
1.3.27 16 08/10/2025
1.3.26 13 08/10/2025
1.3.25 14 08/10/2025
1.3.24 14 08/10/2025
1.3.23 13 08/10/2025
1.3.20 15 08/10/2025
1.3.19 15 08/10/2025
1.3.18 16 08/10/2025
1.3.17 14 08/10/2025
1.3.16 16 08/10/2025
1.3.15 14 08/10/2025
1.3.14 14 08/10/2025
1.3.13 15 08/10/2025
1.3.12 13 08/10/2025
1.3.7 16 08/10/2025
1.3.6 15 08/10/2025
1.3.5 15 08/10/2025
1.3.4 14 08/10/2025
1.3.3 16 08/10/2025
1.3.1 14 08/10/2025
1.2.53 14 08/10/2025
1.2.52 15 08/10/2025
1.2.51 15 08/10/2025
1.2.50 15 08/10/2025
1.2.49 16 08/10/2025
1.2.48 16 08/10/2025
1.2.47 16 08/10/2025
1.2.45 16 08/10/2025
1.2.44 16 08/10/2025
1.2.41 14 08/10/2025
1.2.40 15 08/10/2025
1.2.39 14 08/10/2025
1.2.38 15 08/10/2025
1.2.37 13 08/10/2025
1.2.29 13 08/10/2025
1.2.27 16 08/10/2025
1.2.26 15 08/10/2025
1.2.25 14 08/10/2025
1.2.8 16 08/10/2025
1.2.7 14 08/10/2025
1.2.6 15 08/10/2025
1.2.5 16 08/10/2025
1.2.4 16 08/10/2025
1.2.3 15 08/10/2025
1.1.2 14 08/10/2025
1.1.1 14 08/10/2025
1.0.3 14 08/10/2025
1.0.2 18 08/10/2025
1.0.1 15 08/10/2025
0.9.5 16 08/10/2025
0.9.4 16 08/10/2025
0.9.3 14 08/10/2025
0.9.2 16 08/10/2025
0.9.1 12 08/10/2025
0.8.5 15 08/10/2025
0.8.4 15 08/10/2025
0.8.3 14 08/10/2025
0.8.2 14 08/10/2025
0.8.1 15 08/10/2025
0.7.2 16 08/10/2025
0.6.5 17 08/10/2025
0.6.4 16 08/10/2025
0.6.3 13 08/10/2025
0.6.1 15 08/10/2025
0.5.5 13 08/10/2025
0.5.4 17 08/10/2025
0.5.3 15 08/10/2025
0.5.2 14 08/10/2025
0.5.1 16 08/10/2025
0.4.3 13 08/10/2025
0.3.2 14 08/10/2025
0.3.1 14 08/10/2025
0.2.11 15 08/10/2025
0.2.10 15 08/10/2025
0.2.9 14 08/10/2025
0.2.8 15 08/10/2025
0.2.4 15 08/10/2025
0.2.3 16 08/10/2025
0.2.2 15 08/10/2025
0.2.1 15 08/10/2025
0.1.18 15 08/10/2025
0.1.17 13 08/10/2025
0.1.16 14 08/10/2025
0.1.12 15 08/10/2025
0.1.11 15 08/10/2025
0.1.10 13 08/10/2025
0.1.9 17 08/10/2025
0.1.8 16 08/10/2025
0.1.7 15 08/10/2025
0.1.6 14 08/10/2025