Logging

Component: NServiceBus
NuGet Package NServiceBus (3.x)
Standard support for version 3.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

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

Via IProvideConfiguration

public class ProvideConfiguration :
    IProvideConfiguration<Logging>
{
    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

Samples

Related Articles


Last modified