NServiceBus Host Logging Configuration

Component: NServiceBus Host
NuGet Package NServiceBus.Host (7.x)
Target NServiceBus Version: 6.x
For endpoints using NServiceBus version 7 and above, it is no longer recommended to use the NServiceBus Host version 8. Use alternative approaches such as Generic Host, NServiceBus Windows Service or NServiceBus Docker Container instead. The host is still supported for existing endpoints to ease the transition phase to the new hosting models, refer to the upgrade guide for further details.

This article explains how to customize the logging configuration when using the NServiceBus host. For more details about logging configuration with the built-in profiles, refer to the NServiceBus.Host Profiles - Logging section.

Constructor of IConfigureThisEndpoint implementation

Logging should be customized in the constructor of the class that implements IConfigureThisEndpoint. This is recommended, as this class is the earliest opportunity to initialize any custom logging framework.

If logging is not initialized in the constructor and anything goes wrong during startup of the NServiceBus.Host, errors could be written to the default NServiceBus logging location, and not in the expected custom log output location(s).

Via endpoint configuration

To change the host's logging configuration, implement the IConfigureThisEndoint interface. Provide the custom configuration in the Customize method:

class CustomLogging :
    IConfigureThisEndpoint
{
    public void Customize(EndpointConfiguration configuration)
    {
        LogManager.Use<DefaultFactory>();
    }
}

Samples

Related Articles


Last modified