Skip to content

NLog target that pushes log messages to Graylog using the Http input.

License

Notifications You must be signed in to change notification settings

msoler8785/NLog.Targets.GraylogHttp

 
 

Repository files navigation

NLog.Targets.GraylogHttp

Codacy Badge Apache 2.0 licensed Build status NuGet Dependency Status Dependabot 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

About

NLog target that pushes log messages to Graylog using the Http input.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 93.2%
  • PowerShell 6.8%