Ready to get going? Start your 14 days free trial today

Start free trial

Have an account? Sign in

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

Serilog .NET Core Configuration

Ship logs from ASP.Net Core to Logstash with Serilog

Step 1 - InstallCopy

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 SerilogCopy

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-ssl-port" }
        }
    ],
    "Enrich": [ "FromLogContext" ]
}

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

Step 3 - Using SerilogCopy

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.

Step 4 - .NET Core Logging OverviewCopy

.NET Core is an open-source platform created by Microsoft for development across Linux, macOS & Windows and makes .NET itself run as a cross-platform framework. It can be used to write APIs, and ASP.NET websites.

Tracing & tailing logs for .NET Core can often encounter difficulties when debugging over longer time periods. If these log messages are being recorded across distributed environments then it can make centralising your logs nearly impossible for logging analysis and management at scale.

The Logit platform offers hosted Kibana which makes visualising .NET Core log instances far more streamlined than comparable logging solutions. We believe that monitoring & analysis play a crucial role in maintaining the health of your applications across the cloud & on-premise.

If you need any help with migrating your .NET Core logs to Logstash we are here to help. Feel free to visit our Help Centre or get in contact with our support team by sending us a message via live chat & we'll be happy to assist.

Toggle View

Expand View

Return to Search