Log4net traceappender 不记录任何内容
我想将 log4net 记录的所有内容重定向到 System.Diagnostics Trace 类。我对应该做什么的理解是将 log4net 指向 system.diagnostics.traceappender,然后配置 system.diagnostics。以下是我的 web.config 中的重要部分:
<log4net>
<appender name="trace" type="log4net.Appender.TraceAppender, log4net">
<immediateFlush value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG"/>
<appender-ref ref="trace"/>
</root>
</log4net>
<system.diagnostics>
<sources>
<source name="Console" switchName="DefaultSwitch">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
</listeners>
</source>
<source name="Metabase" switchName="MetabaseSwitch">
<listeners>
<add name="MetabaseListener" />
<remove name="Default" />
</listeners>
</source>
<source name="TextFile" switchName="TextFileSwitch">
<listeners>
<add name="TextFileListener" />
<remove name="Default" />
</listeners>
</source>
</sources>
<sharedListeners>
<!--<add name="ConsoleListener" type="XXX.Manufacturing.Utilities.Diagnostics.ColorConsoleTraceListener,XXX.Manufacturing.Utilities" />-->
<add name ="TextFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextFile.log" />
<add name="MetabaseListener" type="XXX.Manufacturing.Utilities.Diagnostics.MetabaseTraceListener,XXX.Metabase.Proxies" />
</sharedListeners>
<switches>
<add name="MetabaseSwitch" value="Information" />
<add name="DefaultSwitch" value="Verbose" />
<add name="TextFileSwitch" value="Verbose"/>
</switches>
</system.diagnostics>
我是否错过了连接事物的关键步骤?如果我绕过 log4net 并仅创建一个新的跟踪源,它将记录到我的源。
I'd like to redirect everything logged by log4net to the System.Diagnostics Trace classes. My understanding of what I should be doing is pointing log4net at system.diagnostics.traceappender, then I configure system.diagnostics. Here's important parts in my web.config:
<log4net>
<appender name="trace" type="log4net.Appender.TraceAppender, log4net">
<immediateFlush value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG"/>
<appender-ref ref="trace"/>
</root>
</log4net>
<system.diagnostics>
<sources>
<source name="Console" switchName="DefaultSwitch">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
</listeners>
</source>
<source name="Metabase" switchName="MetabaseSwitch">
<listeners>
<add name="MetabaseListener" />
<remove name="Default" />
</listeners>
</source>
<source name="TextFile" switchName="TextFileSwitch">
<listeners>
<add name="TextFileListener" />
<remove name="Default" />
</listeners>
</source>
</sources>
<sharedListeners>
<!--<add name="ConsoleListener" type="XXX.Manufacturing.Utilities.Diagnostics.ColorConsoleTraceListener,XXX.Manufacturing.Utilities" />-->
<add name ="TextFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextFile.log" />
<add name="MetabaseListener" type="XXX.Manufacturing.Utilities.Diagnostics.MetabaseTraceListener,XXX.Metabase.Proxies" />
</sharedListeners>
<switches>
<add name="MetabaseSwitch" value="Information" />
<add name="DefaultSwitch" value="Verbose" />
<add name="TextFileSwitch" value="Verbose"/>
</switches>
</system.diagnostics>
Did I miss a crucial step linking things up? If I bypass log4net and just create a new tracesource it will log to my sources.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我添加了对 XmlConfigurator.Configure() 的调用并打开了内部日志记录。我看到 log4net 正在记录日志,但没有任何内容到达跟踪系统。在使用我的 app.config 一段时间后,我发现一个有效的配置,最显着的变化似乎是放弃了 Systems.Diagnostics 配置中的源并确保设置了 log4net level 属性。工作配置部分:
I added the call to XmlConfigurator.Configure() and turned on internal logging. What I saw was log4net was logging, but nothing was reaching the trace system. After playing with my app.config for a while I found a configuration that worked, most notable changes seemed to be ditching the sources in my Systems.Diagnostics config and making sure the log4net level attribute was set. Working config sections:
您是否调用了
XmlConfigurator.Configure();
方法?如果这不是问题,那么您可以打开内部调试(解释这里)或者配置一个控制台附加器并看看它是否有效。
编辑:我对跟踪系统不太熟悉,但是如果您按如下方式配置跟踪侦听器,您应该获得 log4net 输出:
Did you call the
XmlConfigurator.Configure();
method?If that is not the problem then you can either turn on internal debugging (explained here) or maybe configure a console appender and see if that is working.
Edit: I am not that familiar with the trace system, but if you configure a trace listener as follows you should get the log4net output: