log4net的:与UTC时间登录 [英] Log4Net: Log with UTC times

查看:240
本文介绍了log4net的:与UTC时间登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用log4net的1.2.11.0瓦特/ .NET,我怎么能得到RollingFileAppender进行输出UTC日期?

Using log4net 1.2.11.0 w/ .NET, how can I get the RollingFileAppender to output UTC dates?

据阿帕奇它应该是那么容易,因为:

According to Apache it should be as easy as:

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

不幸的是,这是行不通的。

Unfortunately this is not working.

我的log4net的配置全部是:

The entirety of my log4net configuration is:

  <log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
      <file value="Log-.txt" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd"/>
      <PreserveLogFileNameExtension value="true" />
      <staticLogFileName value="false"/>
      <appendToFile value="true" />
      <maxSizeRollBackups value="10" />
      <dateTimeStrategy type="log4net.Appender.RollingFileAppender+UniversalDateTime" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <root>
      <!-- Options are "ALL", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" and "OFF". -->
      <level value="DEBUG" />
      <appender-ref ref="RollingFile" />
    </root>
  </log4net>

使用反编译器,我可以看到log4net的DLL有型UniversalDateTime为RollingFileAppender进行内部的私有类。

Using a decompiler I can see that the log4net dll has the type 'UniversalDateTime' as a private class inside of RollingFileAppender.

推荐答案

替换%日期%utcdate。

Replace %date by %utcdate.

例如:

<conversionPattern value="%utcdate{ABSOLUTE} UTC %c{1} - %m%n" />

在这个例子中,{}绝对是日期格式说明:请参见 log4net的的PatternLayout更多信息文档

In this example, {ABSOLUTE} is a date format specifier: see The Log4Net PatternLayout documentation for more info.

我怀疑 dateTimeStrategy 可能更多地与确定哪些午夜(本地或UTC)按日期滚动,但我不知道这何时使用。

I suspect dateTimeStrategy may be more to do with determining which midnight (local or UTC) to use when rolling by date, but am not sure about this.

这篇关于log4net的:与UTC时间登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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