OWIN interferes with log4net

删除回忆录丶 提交于 2019-12-10 06:44:21

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!