Search code examples
.netvisual-studiovisual-studio-2010log4nettrace

How do I stop the Visual Studio Output window displaying the logger name of log4net output?


I am using log4net DebugAppender (or TraceAppender). I have configured the appender like this:

<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
    <immediateFlush value="true" />
        <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%level %message%newline" />
    </layout>
</appender>

Loggers in the code are declared in the usual per-class manner:

private static readonly ILog Log = 
    LogManager.GetLogger(typeof(TradingApiRouteCollectionExtensions));

Output in the Output windows looks like this:

Acme.Common.Configuration.TradingApiRouteCollectionExtensions: DEBUG Registering route prefix 'session' for service Acme.Session.SessionService Acme.Common.Configuration.TradingApiRouteCollectionExtensions: DEBUG Web methods found for type Acme.Session.SessionService: Acme.Common.Configuration.TradingApiRouteCollectionExtensions: DEBUG session/

Notice how every line starts with the logger type name. I want to suppress this as I didn't ask for it in the configuration and I don't want it. I can't see any obvious way to do this. Is it possible?


Solution

  • You need to create your own appender. The one you are using does the following:

    System.Diagnostics.Debug.Write(RenderLoggingEvent(loggingEvent), loggingEvent.LoggerName);
    if (!this.m_immediateFlush)
        return;
    System.Diagnostics.Debug.Flush();
    

    Therefore you always end up with the class (logger) name in the output window. You can derive from the log4net Debug appender and override the Append method.