为什么 log4net 仅在我的时记录错误级别是INFO?
我显然不明白log4net。我的根日志级别配置如下:
<root>
<level value="ERROR"/>
<appender-ref ref="FileAppender" />
</root>
我的日志初始化如下所示:
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
我的实际日志记录调用如下所示:
LOG.Error("Error submitting Registration.", exc);
这是有趣的部分。仅当我将根日志级别设置为 INFO 时,此日志语句才有效。为什么日志级别 ERROR 不起作用(我只想要错误,而不想要信息、调试等...)?
I obviously don't understand log4net. My root log level is configured as follows:
<root>
<level value="ERROR"/>
<appender-ref ref="FileAppender" />
</root>
My log initialization looks as follows:
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
And my actual logging call looks as follows:
LOG.Error("Error submitting Registration.", exc);
Here's the funny part. This log statement ONLY works if I set the root log level to INFO. Why does the log level ERROR not work (and I only want errors, not Info, Debug etc...)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我们聪明的架构师的帮助下,我解决了这个问题...
我曾经在 assemblyInfo.cs 中进行日志初始化(但这是错误的)。
我将日志初始化移至 app_startup 中的 global.asax:
server.MapPath 位非常重要,否则 log4net 会尝试从 system32\inetsrv 文件夹中读取其配置。
我认为我以前的日志记录有时会由于程序集加载的顺序或类似的原因而起作用。不管怎样,这个解决方案都是有效的。
With the help of our clever architect I figured this one out...
I used to have my log initialization in assemblyInfo.cs (but this was wrong).
I moved the log initialization to my global.asax in app_startup:
The server.MapPath bit is very important, otherwise log4net tries to read its configuration from the system32\inetsrv folder.
I think my previous logging worked from time to time due to the order in which the assemblies were loaded, or something like that. Either way, this solution works.
我的 log4net-Configfile 中的某人:
编辑:
更好的方法是使用“...”,因为如果您想要此功能,您可以为每个附加程序更改此设置。
Someone of my log4net-Configfile:
Edit:
The better way ist to use "< filter type="log4net.Filter.LevelRangeFilter">..." because you can change this setting for every appender if you want this in feature.