log4net 日志文件在服务重新启动时消失
我们使用 log4net 从 Windows 服务创建日志文件,并使用 RollingFileAppender 根据日期滚动。我们使用的log4net版本是1.2.9。现在来说说这个问题。我们根据日期进行滚动,并且在需要重新启动服务的日子里,不会滚动当天的日志文件。
示例:假设今天是 11 月 16 日。我有包含今天信息的 logfile.txt,还有 logfile.txt.20091115、logfile.txt.20091112 和 logfile.txt.20091111。我丢失了 11/13 和 11/14 的文件,因为服务在这两天都重新启动了。
其他人经历过这种情况或知道为什么会发生这种情况吗?
更新:
这是我的 log4net.config 附加程序部分,
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logfile.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="1000KB" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyyMMdd" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Service Started] " />
<param name="Footer" value="[Service Stopped] " />
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
如您所见,AppendToFile 参数设置为 true。
我想澄清一些事情。当我重新启动服务时,该文件不会被覆盖。当文件应该根据日期滚动时,就是文件消失的时候。
We are using log4net to create our logfiles from Windows services, and we are using the RollingFileAppender rolling based on date. The version of log4net we are using is 1.2.9. Now for the issue. We are rolling based on date, and on the days we need to restart a service the log file for that day is not rolled.
Example: Say today is November 16th. I have logfile.txt that contains today's information, and I have logfile.txt.20091115, logfile.txt.20091112, and logfile.txt.20091111. I am missing the files from 11/13 and 11/14 because the service was restarted on both of those days.
As anyone else experienced this or know why this is happening?
Update:
Here is my log4net.config appender section
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logfile.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="1000KB" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyyMMdd" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Service Started]
" />
<param name="Footer" value="[Service Stopped]
" />
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
As you can see the AppendToFile param is set to true.
I want to clarify something. The file does not get overwritten at the time I restart the service. When the file is suppose to roll based on date, is when the file disappears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 empi 所说,我们需要查看您的配置文件才能确定。不过,我敢打赌您已将
Append
属性设置为 false。来自 log4net 文档:尝试将其添加到您的 RollingFileAppender 配置中:
编辑:查看您发布的配置文件,此行看起来很奇怪:
...记录为:
听起来这与您所看到的相符。尝试删除该行,或将其设置为 false。
As empi says, we'll need to see your config file to tell for sure. However, I'll bet you have the
Append
property set to false. From the log4net docs:Try adding this to your RollingFileAppender config:
EDIT: Looking at your posted config file, this line looks odd:
...which is documented as:
That sounds like it matches what you're seeing. Try removing that line, or setting it to false.