按 utc 日期而不是服务器日期滚动文件
这是我的 log4net.xml 文件
<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,但文件会滚动到服务器时间的第二天。这会导致几个小时的日志被记录在错误的文件中。
如何根据 utc 时间使文件滚动?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般的答案是您需要打开 log4net 并修改它以允许这样做。但是,如果您不想自己完成所有跑腿工作,您可以使用下面链接中发布的代码作为快速启动:
http://old.nabble.com/svn-commit%3A -r398209----logging-log4net-trunk-src-Appender-RollingFileAppender.cs-to4156618.html#a4156618
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