Enterprise Lib 4.0 Logging block and timestamp writing

Topics: Logging Application Block
May 5, 2009 at 5:59 AM
Hi,

I am using Ent Lib 4.0 logging block,

I am doing below action..

func()
{
    Logger.Write("Data"); // With internal time stamp;
    DO Upate database;

}


Here i am facing a problem...the time stamp written in log is newer than the database time.....


For example :


LogEntry has
12:30:01.110000: Data...

Database column time stamp has...
12:30:01.109000

Anybody knows why it is happening...


Thanks and Regards
Nakul






May 5, 2009 at 8:38 AM
Hi,

Does this happen all the time? whenever you run your app, is the result always the same? the database timestamp is always ahead? 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
May 6, 2009 at 5:52 AM

Hi ,

This happens many times and it is reproducible in our code test, 

Some time it behaves correctly.

We are unable to find any solution for this..

Thanks and Regards
Nakul

May 6, 2009 at 7:28 AM

I debugged the source code and found out what's causing the difference in the timestamp.  In one this overload of the Write method :

public
static void Write(object message, ICollection<string> categories, int priority, int eventId, TraceEventType severity, string title, IDictionary<string, object> properties)

    LogEntry
log = new LogEntry();
    .....
}

 

 

which eventually gets called even if you pass a logentry object in the Logger.Write, the instantiation of a new LogEntry causes the TimeStamp to change.  Here is how the LogEntry is returning the TimeStamp value:

public DateTime TimeStamp
{
get
{
    
if (!timeStampInitialized)
    {
       InitializeTimeStamp();
    }
    
return this.timeStamp;
}
set

        
this.timeStamp = value;
        timeStampInitialized =
true;
    }
}

 

 

The instantiation of the LogEntry causes the flag timeStampInitialized to be reset to false and as a result, calls the InitializeTimeStamp and returns a new DateTime.Now.Utc.  The original timestamp is available in the message parameter.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com