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
36
Serilog.Sinks.Console
A Serilog sink that writes log events to the console/terminal.
36
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
36
Serilog.AspNetCore
Serilog support for ASP.NET Core logging
35
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
35
Serilog.Sinks.Console
A Serilog sink that writes log events to the console/terminal.
35
Serilog.Extensions.Hosting
Serilog support for .NET Core logging in hosted services
35
Serilog.Extensions.Logging
Low-level Serilog provider for Microsoft.Extensions.Logging
35
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
34

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