NLog target that pushes log messages to Graylog using the Http input.
C# PowerShell
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
src
tools
.gitignore
CODE_OF_CONDUCT.md
Directory.Build.props
LICENSE
NLog.Targets.GraylogHttp.sln
Nuget.Config
README.md
SA.ruleset
after.NLog.Targets.GraylogHttp.sln.targets
appveyor.yml
build.cake
build.ps1
stylecop.json

README.md

NLog.Targets.GraylogHttp

Apache 2.0 licensed Build status NuGet Dependency Status

This is a custom target for NLog that pushes log messages to Graylog using the Http input.

This library was influenced by EasyGelf

Installation

This library is packaged as a nuget package available here

Install-Package NLog.Targets.GraylogHttp

NetStandard & .net Core

This library runs under netstandard 1.3 and fully supports both netstandard and .net Core.

Usage

Add or modify your NLog Configuration to add the new target and Extension Assembily.

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <extensions>
    <add assembly="NLog.Targets.GraylogHttp"/>
  </extensions>
  <targets>
    <target name="graylog" 
              xsi:type="GraylogHttp" 
              facility="[FACILITY]"
              graylogServer="[SERVER]"
              graylogPort="[PORT]">
        <!-- Location information. -->
        <parameter name="source_method" layout="${callsite}" />
        <parameter name="source_line" layout="${callsite-linenumber}" />
        
        <parameter name="test_prop" layout="${event-context:item=test_prop}" />
      </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" appendTo="graylog"/>
  </rules>
</nlog>

Simple Logging

var logger = LogManager.GetCurrentClassLogger();
logger.Trace("String");
logger.Debug("String");
logger.Warn("String");
logger.Error("String");
logger.Fatal("String");

Advanced Properties

var logger = LogManager.GetCurrentClassLogger();
var e = new LogEventInfo(LogLevel.Fatal, "Test", "Test Message");
e.Properties["test_prop"] = "test property";
logger.Log(e);

References

Gelf Spec