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

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.

Using Serilog

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

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

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.