OWIN干扰log4net [英] OWIN interferes with log4net

查看:167
本文介绍了OWIN干扰log4net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我具有以下日志记录策略/附加程序:

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

  • DebugAppender :如果根级别为DEBUG,则将与DEBUG匹配的每条消息写到默认跟踪侦听器输出中
  • ConsoleAppender :如果应用程序模式(全局上下文属性)为"console",则将WARN上方的每条消息写入控制台输出
  • EventLogAppender :如果应用程序模式(全局上下文属性)为服务",则将ERRROR以上的每条消息写入控制台输出
  • RollingFileAppender :将INFO上方的每条消息写入滚动的平面文件
  • 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

这在整个应用程序中都非常有效,直到第一行使用IAppBuilder界面启动OWIN Web主机.调用WebApp.Start时,我注意到了以下行为:

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:

  • 调试消息(ILogger.Debug)正在写入控制台输出
  • 调试消息(ILogger.Debug)被两次写入VS调试输出

在进一步调查中,我发现OWIN默默地将System.Diagnostics.DefaultTraceListenerSystem.Diagnostics.TextWriterTraceListener的实例附加到默认的跟踪/调试输出,这可能是问题的根源.但是,在app.config中明确声明DefaultTraceListener并没有帮助.

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.

有什么办法可以将OWIN配置得更少……偷偷摸摸?

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");

(名称来自源代码)

这篇关于OWIN干扰log4net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆