简体   繁体   English

重新启动服务后,log4net日志文件消失

[英]log4net log files disappear when service restarted

We are using log4net to create our logfiles from Windows services, and we are using the RollingFileAppender rolling based on date. 我们正在使用log4net从Windows服务创建日志文件,并且正在使用RollingFileAppender基于日期的滚动。 The version of log4net we are using is 1.2.9. 我们使用的log4net版本是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. 示例:今天说11月16日。 I have logfile.txt that contains today's information, and I have logfile.txt.20091115, logfile.txt.20091112, and logfile.txt.20091111. 我有包含今天信息的logfile.txt,并且我有logfile.txt.20091115,logfile.txt.20091112和logfile.txt.20091111。 I am missing the files from 11/13 and 11/14 because the service was restarted on both of those days. 我丢失了11/13和11/14中的文件,因为该两天都重新启动了该服务。

As anyone else experienced this or know why this is happening? 正如其他人经历过的那样,还是知道为什么会这样?

Update: 更新:

Here is my log4net.config appender section 这是我的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]&#13;&#10;" />
    <param name="Footer" value="[Service Stopped]&#13;&#10;" />
    <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
  </layout>
</appender>

As you can see the AppendToFile param is set to true. 如您所见,AppendToFile参数设置为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. 假定文件根据日期滚动,则该文件消失。

As empi says, we'll need to see your config file to tell for sure. 正如empi所说,我们需要查看您的配置文件才能确定。 However, I'll bet you have the Append property set to false. 但是,我敢打赌,您将Append属性设置为false。 From the log4net docs : log4net文档

If the value is set to false then the file will be overwritten, if it is set to true then the file will be appended to. 如果将该值设置为false,则该文件将被覆盖;如果将其设置为true,则该文件将附加到该文件。

Try adding this to your RollingFileAppender config: 尝试将其添加到RollingFileAppender配置中:

 <appendToFile value="true" />

EDIT : Looking at your posted config file, this line looks odd: 编辑 :查看您发布的配置文件,此行看起来很奇怪:

<param name="StaticLogFileName" value="true" />

...which is documented as: ...记录为:

Gets or sets a value indicating whether to always log to the same file. 获取或设置一个值,该值指示是否始终登录到同一文件。 true if always should be logged to the same file, otherwise false. 如果始终应记录到同一文件,则为true,否则为false。

That sounds like it matches what you're seeing. 听起来好像与您所看到的相符。 Try removing that line, or setting it to false. 尝试删除该行,或将其设置为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM