Log4Net

Project Hosting | Nuget: NServiceBus.Log4Net (Version: 1.x)
Target NServiceBus Version: 5.x

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
};
consoleAppender.ActivateOptions();

BasicConfigurator.Configure(consoleAppender);

LogManager.Use<Log4NetFactory>();

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);

NServiceBus.Logging.LogManager.Use<Log4NetFactory>();

Samples


Last modified