如何追踪 log4net 问题 [英] How to track down log4net problems
问题描述
我一直在使用 log4net,但我从未想过的一件事是如何判断内部发生了什么.例如,我的项目中有一个控制台 appender 和一个数据库 appender.我对数据库和代码进行了一些更改,现在数据库附加程序不再工作了.我最终会弄清楚原因,但如果我能看到 log4net 内部发生的事情,那会很有帮助.
log4net 是否会生成任何类型的输出供我查看以尝试确定问题的根源?
首先你必须在应用程序配置文件中设置这个值:
<预><代码><配置><应用设置><add key="log4net.Internal.Debug" value="true"/></appSettings></配置>然后,要确定要保存输出的文件,您可以在同一个 .config 文件中添加以下代码:
<预><代码><配置>...<系统诊断><trace autoflush="true"><听众><添加名称="textWriterTraceListener"type="System.Diagnostics.TextWriterTraceListener"initializeData="C: mplog4net.txt"/></听众></trace></system.diagnostics>...</配置>你可以在下面找到更详细的解释如何启用 log4net 内部调试?"在 log4net 常见问题解答页面中.
I use log4net all the time, but one thing I've never figured out is how to tell what's going on on the inside. For example, I've got a console appender and a database appender in my project. I made a few changes to the database and the code, and now the database appender doesn't work anymore. I'll figure out why eventually, but it would help a lot if I could see what's going on inside log4net.
Does log4net generate any kind of output that I can view to try to determine the source of my problem?
First you have to set this value on the application configuration file:
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
Then, to determine the file in which you want to save the output you can add the following code in the same .config file:
<configuration>
...
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C: mplog4net.txt" />
</listeners>
</trace>
</system.diagnostics>
...
</configuration>
You can find a more detailed explanation under 'How do I enable log4net internal debugging?' in the log4net FAQ page.
这篇关于如何追踪 log4net 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!