Rolling file on utc date rather than server date

爱⌒轻易说出口 提交于 2019-12-07 14:23:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4229232/rolling-file-on-utc-date-rather-than-server-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!