OWIN interferes with log4net

In my application, I have the following strategy / log adding:

  • DebugAppender . If the root level is DEBUG, write every message that matches DEBUG to the default output trace tracer
  • ConsoleAppender . If the application mode (global context property) is "console", write each message above WARN to the console.
  • EventLogAppender . If application mode (global context property) is "service", write each message above ERRROR to the console output.
  • RollingFileAppender : Write each message above INFO to a rolling flat file.

This works very well throughout the application, right down to the very first line, I start the OWIN web host using the interface IAppBuilder

. As soon as I call WebApp.Start

, I noticed the following behavior:

  • Debug messages (ILogger.Debug) are written to console output
  • Debug messages (ILogger.Debug) are written twice to VS debug output

Upon further investigation, I realized that OWIN silently connected copy System.Diagnostics.DefaultTraceListener

and System.Diagnostics.TextWriterTraceListener

to a standard output trace / debug, which may be the root of problems. However, the declaration DefaultTraceListener

in app.config clearly didn't help.

Is there a way to set OWIN to be less ... sneaky?

+3


source to share


1 answer


You can remove listeners in your startup code like:

Trace.Listeners.Remove("HostingTraceListener");
Trace.Listeners.Remove("HostingTraceSource");

      



(Names from source )

+4


source







All Articles