GithubHelp home page GithubHelp logo

nlog.rabbitmq's Introduction

Nlog.RabbitMQ.Target

RabbitMQ Target for popular NLog logging tool

NuGet

Minimum Recommended Configuration

<?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">

  <extensions>
    <add assembly="NLog.Targets.RabbitMQ" />
  </extensions>

  <targets async="true">
    <target name="RabbitMQTarget"
        xsi:type="RabbitMQ"
        useJSON="true"
        layout="${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="RabbitMQTarget"/>
  </rules>

</nlog>

Remember to mark your NLog.config file to be copied to the output directory!

Full Configuration

<?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">

	<extensions>
		<add assembly="NLog.Targets.RabbitMQ" />
	</extensions>

	<targets>
		<!-- these are the defaults (except 'topic' and 'appid'): -->
		<target name="RabbitMQTarget"
				xsi:type="RabbitMQ"
				appid="NLog.RabbitMQ.DemoApp"
				topic="DemoApp.Logging.{0}"
				username="guest" 
				password="guest" 
				hostname="localhost" 
				exchange="app-logging"
				port="5672"
				vhost="/"
				maxBuffer="10240"
				heartBeatSeconds="3"
				Timeout="3000"
				layout="${longdate}|${level:uppercase=true}|${logger}|${message}"
				UseJSON="false"
				UseLayoutAsMessage="false"
				UseSsl="false"
				SslCertPath=""
				SslCertPassphrase=""
				Compression="None"
				DeliveryMode="NonPersistent">
			<field key="threadid" layout="${threadid}" />
			<field key="machinename" layout="${machinename}" />
		</target>
	</targets>

	<rules>
		<logger name="*" minlevel="Trace" writeTo="RabbitMQTarget"/>
	</rules>

</nlog>

Recommendation - async wrapper target

Make the targets tag look like this: <targets async="true"> ... </targets> so that a failure of communication with RabbitMQ doesn't slow the application down. With this configuration an overloaded message broker will have 10000 messages buffered in the logging application before messages start being discarded. A downed message broker will have its messages in the inner target (i.e. RabbitMQ-target), not in the async buffer (as the RabbitMQ-target will not block which is what AsyncWrapperTarget buffers upon).

Important - shutting it down!

Because NLog doesn't expose a single method for shutting everything down (but loads automatically by static properties - the loggers' first invocation to the framework) - you need to add this code to the exit of your application!

LogManager.Shutdown();

Value-Add - How to use with LogStash?

Make sure you are using the flag useJSON='true' in your configuration, then you download logstash! Place it in a folder, and add a file that you call 'logstash.conf' next to it:

input {
  amqp {
    durable => true
    exchange => "app-logging"
    exclusive => false
    format => "json_event"
    host => "localhost"
    key => "#"
    name => ""
    passive => false
    password => "guest"
    port => 5672
    prefetch_count => 10
    ssl => false
    # tags => ... # array (optional)
    type => "nlog"
    user => "guest"
    verify_ssl => false
    vhost => "/"
  }
}

output {
  # Emit events to stdout for easy debugging of what is going through
  # logstash.
  stdout { }

  # This will use elasticsearch to store your logs.
  # The 'embedded' option will cause logstash to run the elasticsearch
  # server in the same process, so you don't have to worry about
  # how to download, configure, or run elasticsearch!
  elasticsearch { embedded => true }
}

You then start the monolithic logstash: java -jar logstash-1.1.0-monolithic.jar agent -f logstash.conf -- web. Now you can surf to http://127.0.0.1:9292 and search your logs that you're generating

nlog.rabbitmq's People

Contributors

adolya avatar snakefoot avatar artdolya avatar 304notmodified avatar

Watchers

James Cloos avatar

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.