EnterpriseLibrary.Logging writes logs with 1 hour difference

跟風遠走 提交于 2019-12-05 02:31:50
DaveRead

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

TomTom

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).

driushkin

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

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;

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.

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