Skip to content

skurdiukov/Graylog.Target

Repository files navigation

Graylog.Target

AppVeyor AppVeyor tests NuGet BCH compliance

Graylog.Target is an NLog target implementation to push log messages to GrayLog2. It implements the Gelf specification and communicates with GrayLog server via UDP.

Solution

Solution is comprised of 3 projects: Target is the actual NLog target implementation, UnitTest contains the unit tests for the NLog target, and ConsoleRunner is a simple console project created in order to demonstrate the library usage.

Usage

Use Nuget:

PM> Install-Package Graylog.Target

Configuration

Here is a sample nlog configuration snippet:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <extensions>
    <add assembly="Graylog.Target"/>
  </extensions>
  <targets>
    <target name="graylog"
            xsi:type="graylog"
            hostip="192.168.1.7 or hostname"
            hostport="12201"
            facility="console-runner" />
    </targets>
    <rules>
      <logger name="*" minlevel="Debug" writeTo="graylog" />
    </rules>
</nlog>

Options are the following:

  • name: arbitrary name given to the target
  • type: set this to "graylog"
  • hostip: IP address or hostname of the GrayLog2 server
  • hostport: Port number that GrayLog2 server is listening on
  • facility: The graylog2 facility to send log messages
  • includeMdlcProperties: If true - includes NLog.MappedDiagnosticsLogicalContext properties in logging properties.
  • serializeObjectProperties: If true - allows to include objects in logging properties. Not recommended for high performance apps.

Code

NLog 4.5+ support structured logging:

_log.Info("Total time elapsed {Elapsed}ms", elapsed);

About

NLog Target for GrayLog2 based on seymen/Gelf4NLog

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages