Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN interferes with log4net

In my application, I've got the following logging strategy/appenders:

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

This works very well throughout the whole application, until the very first line I'm starting the OWIN web host using the IAppBuilder interface. As soon as I invoke WebApp.Start, I noticed the following behavior:

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

Upon further investigation, I figured out that OWIN silently attached an instance of System.Diagnostics.DefaultTraceListener and System.Diagnostics.TextWriterTraceListener to the default trace/debug ouput, which may be the root of the problem. However, declaring the DefaultTraceListener in app.config explicitly didn't help.

Is there any way I can configure OWIN to be less... sneaky?

like image 330
xvdiff Avatar asked Sep 30 '22 03:09

xvdiff


1 Answers

You can remove the listener in startup code, eg:

Trace.Listeners.Remove("HostingTraceListener");

(Name from source code)

like image 143
stuartd Avatar answered Oct 17 '22 14:10

stuartd