Skip to content

Year-2019-20/Gelf4NLog

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gelf4NLog

Gelf4NLog 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 Gelf4NLog.Target

Configuration

Here is a sample nlog configuration snippet:

<configSections>
  <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

	<extensions>
	  <add assembly="Gelf4NLog.Target"/>
	</extensions>

	<targets>
	  <!-- Other targets (e.g. console) -->
    
	  <target name="graylog" 
			  xsi:type="graylog" 
			  hostip="192.168.1.7" 
			  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 of the GrayLog2 server
  • hostport: Port number that GrayLog2 server is listening on
  • facility: The graylog2 facility to send log messages

###Code

//excerpt from ConsoleRunner
var eventInfo = new LogEventInfo
    			{
					Message = comic.Title,
					Level = LogLevel.Info,
				};
eventInfo.Properties.Add("Publisher", comic.Publisher);
eventInfo.Properties.Add("ReleaseDate", comic.ReleaseDate);
Logger.Log(eventInfo);

##Contributing Would you be interested in contributing? All PRs are welcome but also see issue #12.

About

NLog Target for GrayLog2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%