Send data via .NET Core to your Logstash instance provided by

.NET Core

Ship logs from ASP.Net Core to Logstash with Serilog

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.

expand view

Expand View

compact view

Compact View

Return to Search
Sign Up