Getting Started
Architecture
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

NServiceBus Host Logging Configuration

Component: NServiceBus Host
NuGet Package: NServiceBus.Host (8.x)
Target Version: NServiceBus 7.x
Starting with NServiceBus version 8, the NServiceBus Host is no longer supported. Refer to the the host upgrade guide for further details and alternatives.
For endpoints using NServiceBus version 7 and above, it is no longer recommended to use the NServiceBus Host. Use alternative approaches such as Generic Host, NServiceBus Windows Service or NServiceBus Docker Container instead.

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 class's constructor that implements IConfigureThisEndpoint. That is recommended, as the class implementing IConfigureThisEndpoint is the earliest opportunity to initialize any custom logging framework.

If logging is not initialized in the constructor and anything goes wrong during the 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