Serilog
Ship logs from your Serilog to Logstash
Send Serilog application logs to your Hosted ELK Logstash instance.
Install Integration
Installing Serilog
You will need to add the Serilog
and Serilog.Sinks.Network
packages.
Install-Package Serilog
Install-Package Serilog.Sinks.Network
Install-Package Serilog.Settings.AppSettings
Configuring Serilog
Add the following app settings 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://@logstash.host:@logstash.sslPort" />
</appSettings>
</configuration>
The serilog:write-to:TCPSink.uri
value must be in the format "protocol://domain:port".
If your Stack is missing a TCP-SSL input then you can send your logs using TCP or UDP instead, but this is not recommended. Talk to support if you need assistance adding a TCP-SSL input to your Stack.
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 (opens in a new tab) for more information.
Check Logit.io for your logs
Data should now have been sent to your Stack.
View My DataIf you don't see take a look at How to diagnose no data in Stack below for how to diagnose common issues.
How to diagnose no data in Stack
If you don't see data appearing in your Stack after following the steps, visit the Help Centre guide for steps to diagnose no data appearing in your Stack or Chat to support now.
Serilog Logging Overview
Serilog is a popular logging library for .NET and unlike many other logging libraries, it has been built with a focus on presenting log data in a structured & organised format. These event log (opens in a new tab) messages & log files are preserved in the JSON format.
Without needing to alter your code, Serilog uses sinks to send logs in a text-based format to a centralised log management platform for further processing. If you can't or don't wish to use Serilog for structured logging, alternatively you can use either NLog or log4net for migrating your log data from .Net.
For alerting & monitoring, many Serilog users use an email sink for writing events to SMPT. This will quickly leave your inbox flooded when your application encounters an issue. A far less troublesome alternative to this can be to use an intuitive alerting and error monitoring platform that allows you to define alerts with a higher level of customisation & outputs to Slack, Asana, or WebHooks.
Logit.io provides alerting & monitoring as part of our platform that can be customised to output events to many popular third party tools. Our platform provides a completely managed Elastic Stack solution allowing you to get the best out of your .Net logs and provides a Serilog log analyser across all plans.
If you need any more help with shipping Serilog logs to Logstash our team are here to help. Feel free to get in contact with our support team via live chat and we'll be happy to assist.