Log4Net

Project Hosting | Nuget: NServiceBus (Version: 3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

Support for writing all NServiceBus log entries to Log4Net.

Usage

Edit
var layout = new PatternLayout
{
    ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"
};
layout.ActivateOptions();
var consoleAppender = new ConsoleAppender
{
    Threshold = Level.Debug,
    Layout = layout
};
// Note that no ActivateOptions is required since NSB 3 does this internally

// Pass the appender to NServiceBus
SetLoggingLibrary.Log4Net(null, consoleAppender);

Filtering

NServiceBus can write a significant amount of information to the log. To limit this information use the filtering features of the underlying logging framework.

For example to limit log output to a specific namespace.

Here is a code configuration example for adding a Filter.

The Filter

Edit
public class NServiceBusLogFilter :
    FilterSkeleton
{
    public override FilterDecision Decide(LoggingEvent loggingEvent)
    {
        if (loggingEvent.LoggerName.StartsWith("NServiceBus."))
        {
            if (loggingEvent.Level < Level.Warn)
            {
                return FilterDecision.Deny;
            }
        }
        return FilterDecision.Accept;
    }
}

Using the Filter

Edit
var appender = new ConsoleAppender
{
    Threshold = Level.Debug,
    Layout = new SimpleLayout(),
};

appender.AddFilter(new NServiceBusLogFilter());
appender.ActivateOptions();

BasicConfigurator.Configure(appender);

SetLoggingLibrary.Log4Net();

Samples


Last modified