Component: NServiceBus
NuGet Package NServiceBus (7.x - 7.1)

Default Logging

NServiceBus has some limited, and opinionated, logging built in.

The default logging behavior is as follows:

This is applicable to both self hosting and using the NServiceBus Host


All Info (and above) messages will be piped to the current console.

Errors will be written with ConsoleColor.Red. Warnings will be written with ConsoleColor.DarkYellow. All other message will be written with ConsoleColor.White.


All Warn (and above) messages will be written to Trace.WriteLine.

Rolling File

All Info (and above) messages will be written to a rolling log file.

This file will keep 10MB per file and a maximum of 10 log files.

The default logging directory will be HttpContext.Current.Server.MapPath("~/App_Data/") for websites and AppDomain.CurrentDomain.BaseDirectory for all other processes.

The default file name will be nsb_log_yyyy-MM-dd_N.txt, where N is a sequence number for when the log file reaches the max size.

Changing the defaults

With code both the Level and the logging directory can be configured. To do this, use the LogManager class.

var defaultFactory = LogManager.Use<DefaultFactory>();

Logging Levels

The Logging level, or "Threshold", indicates the log levels that will be outputted. So for example a value of Warn would mean all Warn, Error and Fatal message would be outputted.

The supported logging levels are

  • Debug
  • Info
  • Warn
  • Error
  • Fatal

Changing the Logging Level

Configuring this feature via app.config, IConfigurationProvider, or IProvideConfiguration is deprecated in Version 7.
var defaultFactory = LogManager.Use<DefaultFactory>();

Custom Logging

For more advanced logging, it is recommended to utilize one of the many mature logging libraries available for .NET.

Moving to custom logging means the default logging approaches are replaced.

When to configure logging

It is important to configure logging before any endpoint configuration is done since logging is configured in the static context of each NServiceBus class. It should be configured as early as possible at the startup of the app. For example

Unit testing

Unit testing of logging is supported by the NServiceBus.Testing library.


Related Articles

Last modified