Code Monkey home page Code Monkey logo

nlog.targets.gelf's Introduction

#NLog.Targets.Gelf

NLog.Targets.Gelf is a custom target for NLog version 2.0 and Graylog2 server versions 0.9.5p2 and 0.9.6p1.
Shorter messages and longer chunked messages should work for both versions.

To use NLog.Targets.Gelf just add the following to your config file and place NLog.Targets.Gelf.dll in the same location as the NLog.dll file:

<nlog>
	<extensions>
		<add assembly="NLog.Targets.Gelf" />
	</extensions>

	<targets>
		<target name="Gelf" type="Gelf" gelfserver="" port="12201" maxchunksize="8154" graylogversion="0.9.5" />
	</targets>
	<rules>
		<logger name="*" minLevel="Trace" appendTo="Gelf"/>
	</rules>
</nlog>

Just remember to add in your server URL (without http://) or IP address.

Because of differences in the Graylog2 server you need to specify the version as "0.9.5" or "0.9.6" otherwise long message chunking won't work. The default is "0.9.5" if it's left out.

This project was an amalgamation of NLog.Targets.Syslog and Gelf4Net.

Thanks to those guys for their code.

This project is also using Newtonsoft.Json for json serialization.

nlog.targets.gelf's People

Contributors

karelm avatar nareshtripathi avatar simongreen76 avatar smalldave avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

nlog.targets.gelf's Issues

Socket address type SocketException

When you create your SocketClient you are not specifying an address family. If you are contacting a server on a different address type (in my case from an IPv6 Azure web app to an IPv4 gelf target) it throws an address incompatible with protocol error:
[SocketException (0x273f): An address incompatible with the requested protocol was used] System.Net.Sockets.Socket.SendTo(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP) +2896915 NLog.Targets.Gelf.GelfTarget.SendMessage(String gelfServer, Int32 serverPort, String message) +202 NLog.Targets.Gelf.GelfTarget.Write(LogEventInfo logEvent) +184 NLog.Targets.Target.Write(AsyncLogEventInfo logEvent) +69

I grabbed the source and specified the address family to make it work correctly:
Ideally SendMessage would use gelfAddress.AddressFamily to identify what socket to use.

private static readonly Socket SocketClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
private static readonly Socket SocketClientV6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);

private void SendMessage(string gelfServer, int serverPort, string message)
{
var endPoint = GetIPEndPoint(gelfServer, serverPort);
var thisSock = endPoint.AddressFamily == AddressFamily.InterNetworkV6 ? SocketClientV6 : SocketClient;
...
thisSock.SendTo(messageChunkFull, 0, messageChunkFull.Length, SocketFlags.None, endPoint);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.