Timestamp format in Database(Logging) log entry

Topics: Exception Handling Application Block, Logging Application Block
Dec 10, 2007 at 1:29 PM
Edited Dec 10, 2007 at 1:36 PM
In dbCategory in Logging Block formatters i gave Timestamp: {timestamp}.
but Timestamp column and FormattedMessage is coming different time.

Message Colum coming currect IST format .

Why Time Coming wrong in these two columns( Timestamp and FormattedMessage)?

Plz Help me
*********************************************************************************************************

Columns in Log Table in Logging Database

LogID 1
Priority 1
Severity Error

Title SQL Exception in Data Access Layer

Timestamp 12/10/2007 1:06:48 PM

Message 12/10/2007 18:36:47

FormattedMessage TimeStamp : 12/10/2007 1:06:48 PM





<!--==================================================
Logging Application Block
==================================================-->
<loggingConfiguration name="Logging Application Block" tracingEnabled="false"
defaultCategory="" logWarningsWhenNoCategoriesMatch="false">
<listeners>
<add databaseInstanceName="loggingDB_ConnectionString" writeLogStoredProcName="WriteLog"
addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database"
name="Database Trace Listener" />
<add fileName="trace.log" header="----------------------------------------"
footer="----------------------------------------" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
name="FlatFile TraceListener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="dbCategory">
<listeners>
<add name="Database Trace Listener" />
</listeners>
</add>
<add switchValue="All" name="flatFileCategory">
<listeners>
<add name="FlatFile TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>

********Exception Policy in Exception Block*****************************************
<add name="DA Layer Policy">
<exceptionTypes>
<add type="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="None" name="SqlException">
<exceptionHandlers>
<add logCategory="dbCategory" eventId="100" severity="Error"
title="SQL Exception in Data Access Layer " formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="1" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"
name="Logging Handler" />
</exceptionHandlers>
</add>
<add type="System.Data.SqlTypes.SqlNullValueException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="None" name="SqlNullValueException">
<exceptionHandlers>
<add logCategory="dbCategory" eventId="100" severity="Error"
title="SQL Null Value Exception in Data Access Layer " formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="1" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"
name="Logging Handler" />
</exceptionHandlers>
</add>
<add type="System.Data.SqlTypes.SqlTypeException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="SqlTypeException">
<exceptionHandlers>
<add logCategory="dbCategory" eventId="100" severity="Error"
title="SQL Type Exception in Data Access Layer " formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="1" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
Dec 10, 2007 at 9:39 PM
Hi,

What's your time zone?

Fernando
Dec 11, 2007 at 4:06 AM
Edited Dec 11, 2007 at 4:12 AM

Thank fsimonazzi,

I am using IST (Indian Standard Time).

I given Timestamp: {timestamp} in format template.

Message Colum having holding error message like processId,TimeStamp and soon
In that time is coming IST (Indian Standard Time). but them main column TimeStamp and FormattedMessage displaying different time.

How can i solve this problem. plz help me..........


*******************************************************************************************
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
name="Text Formatter" />
</formatters>
****************************************************************************




fsimonazzi wrote:
Hi,

What's your time zone?

Fernando

Dec 27, 2007 at 5:24 PM
Hi,

The Message property is provided by the application code, so the fact that the IST date is shown there is really up to the app.

What goes in the formatted message is managed by the Formatter. You could use the local modifier on the timestamp token to format the date to use your timezone (see http://blogs.msdn.com/tomholl/archive/2006/01/22/516055.aspx for some information on this).

Finally, the date logged to the database does contain the timezone information, so you would expect to be able to convert it to the desired output. It doesn't seem to be the case for SQL Server 2005 though.

Fernando
Dec 27, 2007 at 5:25 PM
Edited Dec 27, 2007 at 5:30 PM
[removed duplicate]