2
votes

I am using log4net for logging in my windows service, it is working fine on XP, 7, 8, Windows Server 2003.

But when it comes to Windows 2012 server (also contains SQL server 2012 in it) log4net is not logging/updating the logs.

Log file is not updating after performing some operations in windows service. It needs restart of windows service to update the logs. Last/recent logs can be seen only after service restart.

     <log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="Log\MyLog_" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <datePattern value="yyyyMMdd.lo\g" />
  <maxSizeRollBackups value="6" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <!--<conversionPattern value="%date %level %logger - %message%newline%exception"/>-->
    <param name="ConversionPattern" value="%date %-5level %-60logger - %-10message%newline%exception" />
  </layout>
</appender>
<appender name="SnFApp" type="log4net.Appender.RollingFileAppender">
  <file value="Log\MyLog1_" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <datePattern value="yyyyMMdd.lo\g" />
  <maxSizeRollBackups value="6" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <!--<conversionPattern value="%date %level %logger - %message%newline%exception"/>-->
    <param name="ConversionPattern" value="%date %-5level %-60logger - %-10message%newline%exception" />
  </layout>
</appender>
<logger name="TransactionManager.SaFManager.ClCCTaMPOSSaFManager">
  <appender-ref ref="SnFApp" />
</logger>
<root>
  <level value="DEBUG" />
  <appender-ref ref="RollingFileAppender" />
</root>
<logger name="Log4NetTest.OtherClass">
  <level value="DEBUG" />
  <appender-ref ref="ConsoleAppender" />
</logger>

2
could you provide logger configuration?starteleport
Added log4net configuration in my question, not able to add here.Sujeet Saste

2 Answers

1
votes

As far as I'm concerned, it locks file exclusively by default. Could you try if this helps?

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

We've got it running on 2012 Server, too, without this issue.

0
votes

It seems that you see the following behavior on Windows 2012 server, the logging is working, only the file timestamp is not updated:

file-date-modified-property-are-not-updating-while-modifying-a-file-without-closing-it

These days, we are monitoring this issue: when one was developing a utility that monitors log files as they are updated.

On 2003, opening the log file folder in explorer, you can see the timestamp and files size change before your eyes each time the log is updated.

On 2008, "Last Modified" field on log files is not updated unless another program attempts to open the file or the utility is stopped, even if F5 is pressed to refresh the view.

Explorer gets is information from NTFS, by using a cmd prompt and "dir" we found that the NTFS metadata for the files is not updated until the handle to a file is closed.