当滚动样式设置为日期时,log4net 有时不会滚动日志文件
我有一个 Windows C# 应用程序,它使用 log4net 进行日志记录。这就是记录器的配置方式:
<log4net>
<appender name="DebugFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Local\logs\ApplnTrace.log" />
<threshold value="INFO" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%5p] - (%file:%line) %m%n" />
</layout>
</appender>
<appender name="MSGFileAppender" type="log4net.Appender.RollingFileAppender">
<file value=".\local\logs\MsgTrace.log" />
<threshold value="INFO" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d %n%m%n" />
</layout>
</appender>
<logger name="ApplnLogger">
<appender-ref ref="DebugFileAppender" />
</logger>
<logger name="MsgLogger">
<appender-ref ref="MSGFileAppender" />
</logger>
</log4net>
文件有时根据日期滚动,有时不滚动,当文件不滚动时,日志记录也会停止。有人能帮我找出原因吗?
I have a Windows C# application which uses log4net for logging. This is how the loggers are configured:
<log4net>
<appender name="DebugFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Local\logs\ApplnTrace.log" />
<threshold value="INFO" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%5p] - (%file:%line) %m%n" />
</layout>
</appender>
<appender name="MSGFileAppender" type="log4net.Appender.RollingFileAppender">
<file value=".\local\logs\MsgTrace.log" />
<threshold value="INFO" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d %n%m%n" />
</layout>
</appender>
<logger name="ApplnLogger">
<appender-ref ref="DebugFileAppender" />
</logger>
<logger name="MsgLogger">
<appender-ref ref="MSGFileAppender" />
</logger>
</log4net>
The files are rolled over based on date sometimes and sometimes does not and when files are not rolled over, the logging also stops. Can anybody help me find out why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
log4Net 被设计为静静地失败。当事情停止工作时,通常会出现问题(最常见的是配置问题或文件系统安全问题)。
您可能想尝试启用内部 log4net 调试。将此密钥放入 app.config 的
元素中:然后启动您的应用。 Log4net 会输出一堆调试信息。它被写入 System.Console 和 System.Diagnostics.Trace 系统。您可以从附加的调试器捕获跟踪消息,或者通过在 app.config 文件中添加跟踪侦听器来捕获跟踪消息。如果跟踪侦听器写入文件,请确保您的进程具有写入访问权限,否则您将看不到任何内容:
有一个 您可以在此处连接的不同跟踪侦听器的数量,包括写入 Windows 事件系统的侦听器。
更多信息:
log4Net is designed to fail quietly. When things stop working, there's usually a problem (most often, it's a config issue or a filesystem security issue).
You might want to try enabling internal log4net debugging. Park this key in the
<appSettings>
element of your app.config:then start your app. Log4net will spew a bunch of debugging info. It gets written to System.Console and to the System.Diagnostics.Trace system. You can catch the trace messages from an attached debugger or by adding a trace listener in the app.config file. If the trace listener writes to a file, make sure that your process has write access, otherwise you'll see nothing:
There are a number of different trace listeners you can wire up here, including ones that write to the windows event system.
More here:
没有来源,很难说。应用程序是否也停止工作?如果是,请找出您的应用程序中的致命缺陷。
如果没有,从 log4net JIRA 来看,RollingFileAppender 存在很多问题(请参阅:log4net JIRA) :
"RollingFileAppender 间歇性停止日志记录尝试滚动日志文件”
"RollingFileAppender 与rollingStyle="Date" 和MaximumFileSize 两者不能同时工作。”
也许这是伤害您的问题之一。
Without source, it's hard to tell. Does the application also stop working? If yes, find the fatal flaw in your application.
If not, judging from the log4net JIRA, there's plenty of issues with the
RollingFileAppender
(see: log4net JIRA) :"RollingFileAppender stops logging intermittently when it tries to roll over the log file"
"RollingFileAppender with rollingStyle="Date" and maximumFileSize both are not working Simultaneously."
Maybe it's one of those issues that's hurting you.