NServiceBus Host Logging configuration

Component: NServiceBus Host
NuGet NServiceBus.Host (5.x)
Target NServiceBus Version: 5.x

Logging configuration

This article explains how to customize default configuration. Refer to the Profiles - Logging section for more details about logging configuration in built-in profiles.

Logging configuration for NServiceBus Host can be customized by providing endpoint configuration or using profiles.

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(BusConfiguration configuration)
    {
        LogManager.Use<DefaultFactory>();
    }
}

Via profiles

Logging levels and sinks need to be defined before configuring other components, therefore logging profile configuration is kept separate from other profile behaviors and requires implementing a dedicated interface.

To customize logging for a given profile, create a class implementing IConfigureLoggingForProfile<T> where T is the profile type:

public class YourProfileLoggingHandler :
    NServiceBus.Hosting.Profiles.IConfigureLoggingForProfile<YourProfile>
{
    public void Configure(IConfigureThisEndpoint specifier)
    {
        // setup logging infrastructure
        LogManager.Use<Log4NetFactory>();
    }

}
One class can configure logging for multiple profile types. However, it is not possible to spread logging configuration for a single profile across multiple classes.

The host's profiles mechanism can be used to specify different logging levels (DEBUG, WARN, etc.) or targets (CONSOLE, FILE, etc.).

For more details refer to the Host Custom Logging, Host Profile Logging and Host Default Logging samples.

Samples

Related Articles

  • Logging
    Manage and integrate with NServiceBus logging.

Last modified