Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rolling file on utc date rather than server date

This is my log4net.xml file

<log4net>
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="C:\MVC2-" > </file>
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <datePattern value="yyyy'-'MM'-'dd'.log'" />

    <dateTimeStrategy type="log4net.Appender.RollingFileAppender+UniversalDateTime" />

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

    <staticLogFileName value="false" />

    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%utcdate %level %property{requestId} %thread %logger - %message%newline" />
    </layout>
  </appender>

  <root>
    <level value="DEBUG" />
    <appender-ref ref="RollingFile" />
  </root>
</log4net>

The log dates are in UTC, but the file rolls over to the next day on server time. This results in some hours of logs being recorded in the wrong file.

How do I make the file roll over depending upon the utc time?

like image 303
nsdiv Avatar asked Nov 15 '22 05:11

nsdiv


1 Answers

The general answer is that you are going to need to open up log4net and modify it to allow this. However, if you don't want to do all the legwork yourself, you could use the code posted in the link below to use as a jump-start:

http://old.nabble.com/svn-commit%3A-r398209----logging-log4net-trunk-src-Appender-RollingFileAppender.cs-to4156618.html#a4156618

like image 119
IAmTimCorey Avatar answered Dec 04 '22 09:12

IAmTimCorey