English 中文(简体)
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. 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]&#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.

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. However, I ll bet you have the Append property set to false. From the log4net docs:

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.

Try adding this to your RollingFileAppender config:

 <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.

That sounds like it matches what you re seeing. Try removing that line, or setting it to false.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签