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

Serilog

Ship logs from your serilog to logstash

Step 1 - Install

Installing Serilog You will need to add the Serilog and Serilog.Sinks.Network packages. This guide will also use appSettings to configure Serilog.

Install-Package Serilog
Install-Package Serilog.Sinks.Network
Install-Package Serilog.Settings.AppSettings

Step 2 - Configuring Serilog

Add AppSettings to your app.config or web.config.

<configuration>
    <appSettings>
        <!-- Level of logging -->
        <add key="serilog:minimum-level" value="Verbose" />
        <!-- Use the TCP Network sink -->
        <add key="serilog:using:TCPSink" value="Serilog.Sinks.Network" />
        <!-- Your logstash configuration -->
        <add key="serilog:write-to:TCPSink.uri" value="tls://your-logstash-host:your-port" />            
    </appSettings>
</configuration>

The serilog:write-to:TCPSink.uri value must be in the format "protocol://domain:port".

Step 3 - Using Serilog

Create a statically accessible Logger configured from AppSettings.

Log.Logger = new LoggerConfiguration()
    .ReadFrom.AppSettings()
    .CreateLogger();

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 Documentation for more information.

expand view

Expand View

compact view

Compact View

Return to Search
Sign Up