Click to See Complete Forum and Search --> : Enterprise Library


balamurali_g
October 2nd, 2006, 10:36 AM
I am using Enterprise Library for logging for my Windows Service ,i developed using . NET . It logs to a database ,in aremote server. I set the TraceOutputOption to DateTime. It logs ,showing right Date,but time is 5 hours ahead of the current time.
Any ideas,how to fix this.
I would appreciate,is someone has a fix for this.Thanks .

Rohit Kukreti
October 3rd, 2006, 08:12 AM
Are you logging on to a database or a local file? Also, is your service running on local machine or a remote server/machine?

balamurali_g
October 4th, 2006, 10:17 AM
I fixed this myself.The problem was,the Enterprise Library Timestamps in UTC time (Coordinated Universal time) by default . To make it stamp with current system time, ihad to do this ,modify the Timestamp Token class. This class is used by the Text Formatter to configure the app.

public override string FormatToken(string tokenTemplate, LogEntry log)
{
if (tokenTemplate.Equals("local",System.StringComparison.
InvariantCultureIgnoreCase))
{
System.DateTime localTime=log.TimeStamp.ToLocalTime();
return localTime.ToString();
}
else if (tokenTemplate.StartsWith("local:",System.StringComparison.
InvariantCultureIgnoreCase))
{
string formatTemplate = tokenTemplate.Substring(6);
System.DateTime localTime = log.TimeStamp.ToLocalTime();
return localTime.ToString(formatTemplate, CultureInfo.CurrentCulture);
}
else
{
return log.TimeStamp.ToString(tokenTemplate, CultureInfo.CurrentCulture);
}
}

Also in LogEntry.cs ,in CollectIntrinsic() method,modify the DateTime.UtcNow to DateTime.Now. These .cs files are in C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\Formatters\TimeStampToken.cs and
C:\Program Files\Microsoft Enterprise Library January 2006\src\Logging\LogEntry.cs


Thanks for replying ,anyways .