Gelf4NLog is an [NLog] target implementation to push log messages to [GrayLog2].
Branch: develop
Clone or download
GokGokalp Update README.md
Readme updated.
Latest commit 02f3e50 May 18, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
NLog.Web.AspNetCore.Targets.Gelf.ConsoleRunner Some updates & refactoring... May 18, 2018
NLog.Web.AspNetCore.Targets.Gelf.Tests adding MappedDiagnosticsLogicalContext data to gelf message May 3, 2018
NLog.Web.AspNetCore.Targets.Gelf Some updates & refactoring... May 18, 2018
.gitattributes first commit Jun 18, 2017
.gitignore first commit Jun 18, 2017
LICENSE
NLog.Web.AspNetCore.Targets.Gelf.1.1.0.nuspec Some updates & refactoring... May 18, 2018
README.md Update README.md May 18, 2018
build.ps1 first commit Jun 18, 2017
docker-compose.yml Some updates & refactoring... May 18, 2018

README.md

NLog.Web.AspNetCore.Targets.Gelf

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

NuGet version

History

Code forked from https://github.com/2020Legal/NLog.Targets.Gelf which is a fork from https://github.com/akurdyukov/Gelf4NLog who forked the origonal code from https://github.com/seymen/Gelf4NLog

I transformed the project to .NET Core.

Usage

Use Nuget:

$ dotnet add package NLog.Web.AspNetCore.Targets.Gelf

Configuration

Here is a sample nlog.config configuration file for graylog:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off"
      internalLogFile="c:\temp\internal-nlog.txt">
  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
    <add assembly="NLog.Web.AspNetCore.Targets.Gelf"/>
  </extensions>
  <targets>
    <target xsi:type="File" name="debugFile" filename="C:\@Logs\${shortdate}-${level}-${applicationName}.txt" layout="${longdate}|${level:upperCase=true}|${logger}|${aspnet-Request-Method}|url: ${aspnet-Request-Url}${aspnet-Request-QueryString}|${message}" concurrentWrites="false" />
    <target xsi:type="Gelf" name="graylog" endpoint="udp://192.168.99.100:12201" facility="console-runner" SendLastFormatParameter="true">
	
	<!-- Optional parameters -->
	<parameter name="param1" layout="${longdate}"/>
	<parameter name="param2" layout="${callsite}"/>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="debugFile, graylog" />
  </rules>
</nlog>

Options are the following:

  • name: arbitrary name given to the target
  • xsi:type: set this to "gelf"
  • endpoint: the uri pointing to the graylog2 input in the format udp://{IP or host name}:{port} note: support is currently only for udp transport protocol
  • facility: The graylog2 facility to send log messages
  • sendLastFormatParameter: default false. If true last parameter of message format will be sent to graylog as separate field per property

###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);

or alternatively for simple log messages

Logger.Info("Simple message {0}", value);

or alternatively for use of sendLastFormatParameter

Logger.Info(comic.Title, new { Publisher = comic.Publisher, ReleaseDate = comic.ReleaseDate });

will log Publisher and ReleaseDate as separate fields in Graylog