Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

NLog

NuGet Package: NServiceBus.NLog (3.x)
Target Version: NServiceBus 7.x

Support for writing all NServiceBus log entries to NLog.

Usage

var config = new LoggingConfiguration();

var consoleTarget = new ColoredConsoleTarget
{
    Layout = "${level}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}"
};
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));

LogManager.Configuration = config;

NServiceBus.Logging.LogManager.Use<NLogFactory>();

Filtering

NServiceBus can write a significant amount of information to the log. To limit this information use the filtering features of the underlying logging framework.

For example to limit log output to a specific namespace.

Here is a code configuration example for adding a Rule.

var config = new LoggingConfiguration();

var target = new ColoredConsoleTarget();
config.AddTarget("console", target);
config.LoggingRules.Add(new LoggingRule("MyNamespace.*", LogLevel.Debug, target));

LogManager.Configuration = config;

NServiceBus.Logging.LogManager.Use<NLogFactory>();

Additional exception data

Starting from NServiceBus version 7.2, exceptions from message processing might contain additional error information in the Exception.Data property. Use the Data format property when configuring the exception layout, e.g. ${exception:format=toString,Data}. For more information, see the Exception layout renderer documentation.

Samples