Skip to content

A Serilog sink sending UDP packages over the network.

License

Notifications You must be signed in to change notification settings

nbaztec/serilog-sinks-udp

 
 

Repository files navigation

Serilog.Sinks.Udp - A Serilog sink sending UDP packages over the network

Build status NuGet Version NuGet Documentation Join the chat at https://gitter.im/serilog/serilog Help

Package - Serilog.Sinks.Udp | Platforms - .NET 4.5, .NETStandard 1.3

Table of contents


Super simple to use

In the following example, the sink will send UDP packages on the network to localhost on port 7071.

Serilog.ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.Udp(IPAddress.Loopback, 7071)
  .CreateLogger();

Used in conjunction with Serilog.Settings.Configuration the same sink can be configured in the following way:

{
  "Serilog": {
    "MinimumLevel": "Verbose",
    "WriteTo": [
      {
        "Name": "Udp",
        "Args": {
          "remoteAddress": "127.0.0.1",
          "remotePort": 7071
        } 
      }
    ]
  }
}

Configuration using Serilog.Settings.Configuration enables the possibility to specify a hostname instead of an IP address as the remote address.

Typical use case

Producing log events is only half the story. Unless you are consuming them in a matter that benefits you in development or production, there is really no need to produce them in the first place.

In development I've been sending UDP packages to the loopback address, and use Log2Console to visualize them. It supports UDP receivers, and allows me to filter and search according to my needs.

Taking it to the next level is when you as a team agree on sending the log events to a multicast address, making them accessible to all team members. This can be beneficial for Quality Assurance who wishes to monitor log events from all instances of your running application.

Event formatters

The event formatter is an output template on steroids. It has the responsibility of turning a single log event into a textual representation. It can serialize the log event into JSON, XML or anything else that matches the expectations of the receiver.

The sink comes pre-loaded with two XML based event formatters. One is matching the log4j schema expected by Log2Console and the other is matching the log4net schema expected by Log4View.

Log4jTextFormatter

The log event is formatted according to the log4j XML schema expected by Log2Console.

<log4j:event logger="Some.Serilog.Context" timestamp="1184286222308" level="ERROR" thread="1">
  <log4j:message>Something failed</log4j:message>
  <log4j:throwable>An exception describing the failure<log4j:throwable>
</log4j:event>

Log4netTextFormatter

The log event is formatted according to the log4net XML schema expected by Log4View.

<log4net:event logger="Some.Serilog.Context" timestamp="2017-09-01T22:00:00.000+02:00" level="DEBUG" thread="1" username="MACHINE\username" domain="dotnet">
  <log4net:locationInfo class="Some.Serilog.Context" method="System.String Get(Int32)"/>
  <log4net:properties>
    <log4net:data name="log4net:HostName" value="MACHINE"/>
  </log4net:properties>
  <log4net:message>Something went wrong.</log4net:message>
  <log4net:throwable>System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.</log4net:throwable>
</log4net:event>

Sample applications

The following sample applications demonstrate the usage of this sink in various circumstances:

Install via NuGet

If you want to include the UDP sink in your project, you can install it directly from NuGet.

To install the sink, run the following command in the Package Manager Console:

PM> Install-Package Serilog.Sinks.Udp

Credit

Thank you JetBrains for your important initiative to support the open source community with free licenses to your products.

JetBrains

About

A Serilog sink sending UDP packages over the network.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 96.2%
  • PowerShell 3.8%