Component: NServiceBus
NuGet Package NServiceBus (4.x)
Standard support for version 4.x of NServiceBus has expired. For more information see our Support Policy.

Default Logging

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

The default logging behavior is as follows:

Logging is only enabled in the NServiceBus Host. For self hosting enable the logging using code.

See NServiceBus Host Profiles for the default logging in the NServiceBus Host.

Changing the defaults

This can be achieved by taking full control over the Log4Net integration.

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 Levels are defined by the Log4Net.Level class.

Changing the Logging Level

When logging level is defined in both app.config and code the app.config wins.

Via app.config

  <section name="Logging"
           type="NServiceBus.Config.Logging, NServiceBus.Core" />
<Logging Threshold="Debug" />

Via IProvideConfiguration

public class ProvideConfiguration :
    public Logging GetConfiguration()
        return new Logging
            Threshold = "Info"

Via config API

This can be achieved by taking full control over the Log4Net integration.

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