Step 1 - Install

You will need the main Serilog.AspNetCore package and Serilog.Sinks.Network to send logs using TCP/TLS or UDP.

Serilog.Settings.Configuration is needed to setup Serilog using settings from appsettings.json (instead of hardcoded settings).

Install-Package Serilog.AspNetCore
Install-Package Serilog.Settings.Configuration
Install-Package Serilog.Sinks.Network
Step 2 - Configuring Serilog

Add Serilog settings to your appsettings.json file:

"Serilog": {
    "Using": [ "Serilog.Sinks.Network" ],
    "MinimumLevel": "Error",
    "WriteTo": [
            "Name": "TCPSink",
            "Args": { "uri": "tls://your-logstash-host:your-port" }
    "Enrich": [ "FromLogContext" ]

The uri value must be in the format protocol://domain:port.

Step 3 - Using Serilog

Inside Program.cs, add Serilog to the WebHost build process:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
       .UseSerilog((ctx, config) => { config.ReadFrom.Configuration(ctx.Configuration); })

You can now log from anywhere in your application.

Log.Information("The global logger has been configured");

Serilog is a fully featured logging framework and has many other capabilities that are not detailed here.

Please see the Serilog.AspNetCore Documentation for more information.

Ready to get going?

Try our 14 day free trial

No commitment and no catches

Create Free Trial