NLog.Extensions.RabbitMQ 2.7.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package NLog.Extensions.RabbitMQ --version 2.7.6
                    
NuGet\Install-Package NLog.Extensions.RabbitMQ -Version 2.7.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NLog.Extensions.RabbitMQ" Version="2.7.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NLog.Extensions.RabbitMQ" Version="2.7.6" />
                    
Directory.Packages.props
<PackageReference Include="NLog.Extensions.RabbitMQ" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NLog.Extensions.RabbitMQ --version 2.7.6
                    
#r "nuget: NLog.Extensions.RabbitMQ, 2.7.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NLog.Extensions.RabbitMQ@2.7.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NLog.Extensions.RabbitMQ&version=2.7.6
                    
Install as a Cake Addin
#tool nuget:?package=NLog.Extensions.RabbitMQ&version=2.7.6
                    
Install as a Cake Tool

Nlog.RabbitMQ.Target

RabbitMQ Target for popular NLog logging tool

NuGet

Forked from https://github.com/adolya/Nlog.RabbitMQ

Changed most of target parameters to be formatted using Layout.Render(...)

Renamed to a different package ID in order to be able to publish a nuget.

Changes for ASPNET.CORE

The following configuration is now supported:

  ...
  
  <target name="NameOfThisTarget"
      xsi:type="RabbitMQ"
      username="${configsetting:name=<String>:default=<Default Value>}"
      password="${configsetting:name=<String>:default=<Default Value>}"
      hostname="${configsetting:name=<String>:default=<Default Value>}"
      port="${configsetting:name=<String>:default=<Default Value>}"
      port="${configsetting:name=<String>:default=<Default Value>}"
      exchange="${configsetting:name=<String>:default=<Default Value>}"
      heartBeatSeconds="30"
      UseJSON="true"
      layout="${message}"
      DeliveryMode="NonPersistent">
    <field key="machineName" name="MachineName" layout="${machinename}"/>
    <field key="url" name="url" layout="${aspnet-request-url}" />
    <field key="callStack" name="callStack" layout="${stacktrace:separator=&#13;&#10;}" />
  </target>
  ...

Given the following config file appsettings.Env.json, in the environment Env:

"Application": {
  "RabbitMQ": {
    "Host": "rabbitmq-server",
    "Port": "5672",
    "Username": "rabbitmquser",
    "Password": "password",
    "Vhost": "/",
    "Exchange": "test.exchange",
  }
}

The following should be in your NLog.config file:


<target name="NameOfThisTarget"
    xsi:type="RabbitMQ"
    username="${configsetting:name=Application.RabbitMQ.Username}"
    password="${configsetting:name=Application.RabbitMQ.Password}"
    hostname="${configsetting:name=Application.RabbitMQ.Host}"
    port="${configsetting:name=Application.RabbitMQ.Port}"
    vhost="${configsetting:name=Application.RabbitMQ.Vhost}"
    exchange="${configsetting:name=Application.RabbitMQ.Exchange}"
    heartBeatSeconds="30"
    UseJSON="true"
    layout="${message}"
    DeliveryMode="NonPersistent">
  <field key="machineName" name="MachineName" layout="${machinename}"/>
  <field key="url" name="url" layout="${aspnet-request-url}" />
  <field key="callStack" name="callStack" layout="${stacktrace:separator=&#13;&#10;}" />
</target>
<?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.RabbitMQ.Target" />
  </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.RabbitMQ.Target" />
	</extensions>

	<targets>
		
		<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();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.7.7 1,035 4/23/2020
2.7.6 609 4/1/2020