EnterpriseLibrary.Logging writes logs with 1 hour difference

不羁岁月 提交于 2019-12-06 23:37:10

问题


we encounter a weird problem with logging. We are using Microsoft.Practices.EnterpriseLibrary.Logging library for logging in our web application and the problem is that it writes the log with 1 hour difference from the current system time.

Our logger is based on this article and the time in a log entry is never set in code by us. Every log entry has a title which looks like this:

MainLogSource Information: 0 : Timestamp: 11/04/2011 10:15:32 so this timestamp always 1 hour earlier than system time (e.g. this entry appeared at 11:15).

Where can be the problem? Thanks


回答1:


By default Enterprise Library logs using UTC timestamp, so these are unaffected by daylight savings time.

You can change the formatter in the .config file to use local time (see attached question), but be aware that this will result in duplicate entries when daylight savings time changes occur.

Enterprise Library 5.0 - Application Logging - Incorrect DateTime




回答2:


Cultural ignorance of one side of the comparison?

As in: the logger writes out the time in UTC and you compare it to the local system time and just happen to have it set to a one hour difference? Central Europe, for example, is 1 hour ahead of UTC time (half of the year).

What are your locale settings? This is a quite common phenomenon. Basically to be comparable loggers etc. LOVE setting things in UTC, and you should do so, too. I know companies running the servers in UTC time locale wise so it is easier to compare logs to the system clock (at the price to the system clock always being off).




回答3:


This is probably because EntLib by default logs timestamps in UTC. You can override this see here




回答4:


Set the TimeStamp property of LogEntry class in your code. You can set it to your local time. This will reflect at both places : TimeStamp and ExtendedProperties. Like Below:

    var newLog = new LogEntry(objException.Message, "General", 1, 1, TraceEventType.Error, "YourApp", null);
    newLog.TimeStamp = DateTime.Now;



回答5:


There are a couple of possibilities that spring to mind:

  • The clock on which ever machine is running the the application hasn't been adjusted for daylight saving time.

  • When getting the time you are requesting it as UTC rather than the current locale's time zone.



来源:https://stackoverflow.com/questions/5620173/enterpriselibrary-logging-writes-logs-with-1-hour-difference

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