在utc日期而不是服务器日期滚动文件 [英] Rolling file on utc date rather than server date

查看:100
本文介绍了在utc日期而不是服务器日期滚动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的log4net.xml文件

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>

日志日期以UTC为单位,但是文件会在服务器时间上滚动到第二天.这会导致数小时的日志记录在错误的文件中.

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.

如何根据utc时间将文件翻转?

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

推荐答案

一般的答案是,您将需要打开log4net并对其进行修改以允许这样做.但是,如果您不想自己做所有的繁琐工作,则可以使用下面链接中发布的代码作为快速入门:

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

这篇关于在utc日期而不是服务器日期滚动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆