Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serilog-contrib/Serilog.Sinks.Network
A serilog network sink. Designed with logstash and the Elastic stack in mind
https://github.com/serilog-contrib/Serilog.Sinks.Network
dotnet dotnet-standard elasticstack elk serilog-sink
Last synced: about 2 months ago
JSON representation
A serilog network sink. Designed with logstash and the Elastic stack in mind
- Host: GitHub
- URL: https://github.com/serilog-contrib/Serilog.Sinks.Network
- Owner: serilog-contrib
- License: apache-2.0
- Created: 2016-11-01T21:45:51.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-09T13:46:22.000Z (about 1 year ago)
- Last Synced: 2024-08-02T18:40:03.479Z (5 months ago)
- Topics: dotnet, dotnet-standard, elasticstack, elk, serilog-sink
- Language: C#
- Homepage:
- Size: 4.32 MB
- Stars: 16
- Watchers: 0
- Forks: 16
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Serilog Network Sink
[![Build status](https://ci.appveyor.com/api/projects/status/dw7y9d3q9ty7cm5h?svg=true)](https://ci.appveyor.com/project/pauldambra/serilog-sinks-network)
Writes the JSON output from serilog log event to either UDP or TCP
# Versions
Serilog Network Sink is targeted **NetStandard 1.3** from version 2.x. It can be used for **.NET Core** based projects.
1.x versions are still targeted to standard .Net Framework 4.5
# Usage
Set up to log via TCP
```csharp
var ip = IPAddress.Parse("1.3.3.7");
var log = new LoggerConfiguration()
.WriteTo.TCPSink(ip, 1337)
.CreateLogger();var urlLogger = new LoggerConfiguration()
.WriteTo.TCPSink("some.url.com", 1337)
.CreateLogger();var urlLogger = new LoggerConfiguration()
.WriteTo.TCPSink("tls://some.fqdn.com:12435")
.CreateLogger();// you can provide any specific formatter ...
var urlLogger = new LoggerConfiguration()
.WriteTo.TCPSink("tls://some.fqdn.com:12435", new RawFormatter())
.CreateLogger();// ... otherwise this will use the default provided LogstashJsonFormatter (described below)
var urlLogger = new LoggerConfiguration()
.WriteTo.TCPSink("tls://some.fqdn.com:12435")
.CreateLogger();```
Or maybe UDP
```csharp
var ip = IPAddress.Parse("1.3.3.7");
var log = new LoggerConfiguration()
.WriteTo.UDPSink(ip, 1337)
.CreateLogger();var urlLogger = new LoggerConfiguration()
.WriteTo.UDPSink("some.url.com", 1337)
.CreateLogger();// you can provide any specific formatter for UDP too ...
var urlLogger = new LoggerConfiguration()
.WriteTo.UDPSink("some.url.com", 1337, new RawFormatter())
.CreateLogger();```
# Configure from the config file
```
```
# JSON structure (LogstashJsonFormatter)
Serilog log JSON tends to look like this:
```
{
"Timestamp": "2016-11-03T16:28:55.0094294+00:00",
"Level": "Information",
"MessageTemplate": "ping: {ping} and pong: {pong}",
"message": "ping: 972 and pong: 973",
"Properties": {
"ping": 972,
"pong": 973,
"application": "ping ponger",
"type": "example",
"environment": "production"
}
}```
The LogstashJsonFormatter flattens that structure so it is more likely to fit into an existing logstash infrastructure.```
{
"timestamp": "2016-11-03T16:28:55.0094294+00:00",
"level": "Information",
"message": "ping: 972 and pong: 973",
"ping": 972,
"pong": 973,
"application": "ping ponger",
"type": "example",
"environment": "production",
}```
# Acknowledgements
Adapted from [Serilog Splunk Sink](https://github.com/serilog/serilog-sinks-splunk) and [Splunk .Net Logging](https://github.com/splunk/splunk-library-dotnetlogging) both Apache 2.0 licensed