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?
You can remove the listener in startup code, eg:
Trace.Listeners.Remove("HostingTraceListener");
(Name from source code)
来源:https://stackoverflow.com/questions/25155980/owin-interferes-with-log4net