Logging Exceptions to database not working properly

Topics: Data Access Application Block, Exception Handling Application Block, Logging Application Block
May 21, 2007 at 4:38 PM
Hi

I am trying to log a simple exception to the database(Entib 3.0 - Exception block + Logging block + DA Block). The exception is getting logged and I DO see the message in the Message and FormattedMessage columns of the Log table of the Loggibg database correctly.
However, only a small portion of the exception is being written. When I log to the rolling trace listener, I get everything(Source, StackTrace, Message, AdditionalProperties etc)

This is what I see in the Logging database for the Message and FormattedMessage columns

Message
HandlingInstanceID: b1fdbb41-4960-4c4d-bde0-2a3023d76ba4
<Exception>
<Description>An exception of type 'System.Exception' occurred and was caught.</Description>
<DateTime>2007-05-20 14:56:08Z</DateTime>
<ExceptionType>System.Exception, mscorlib, Message: HandlingInstanceID: b1fdbb41-4960-4c4d-bde0-2a3023d76ba4

FomattedMessage
<Exception>
<Description>An exception of type 'System.Exception' occurred and was caught.</Description>
<DateTime>2007-05-20 14:56:08Z</DateTime>
<ExceptionType>System.Exception, m

That is all that is being written to the database



This is what my Config file looks like


<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="customExceptionConfiguration" type="CompanyName.ProjectName.Common.Global.ExceptionManagement.EntLibExceptionHandler, CompanyName.ProjectName.Common.Global, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="customLoggingConfiguration" type="CompanyName.ProjectName.Common.Global.Logging.EntLibLogHandler, CompanyName.ProjectName.Common.Global, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="customCachingConfiguration" type="CompanyName.ProjectName.Common.Global.CacheManagement.EntLibCacheHandler, CompanyName.ProjectName.Common.Global, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add databaseInstanceName="LoggingServer" writeLogStoredProcName="WriteLog"
addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Database Trace Listener" />
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Formatted EventLog TraceListener" />
<add fileName="rolling.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd"
rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text Formatter"
header="----------------------------------------" footer="----------------------------------------"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Rolling Flat File Trace Listener" />
</listeners>
<formatters>
<add template="Message: {message}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Database Trace Listener" />
<add name="Rolling Flat File Trace Listener" />
</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>
<exceptionHandling>
<exceptionPolicies>
<add name="GLOBAL_POLICY">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.XmlExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
<dataConfiguration defaultDatabase="LoggingServer" />
<connectionStrings>
<add name="LoggingServer" connectionString="Database=Logging;Server=NYC1-RVENUGOPAL\SQLEXPRESS;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>


Thanks
-RV

PS :- I am able to log lhe same exception in full using the RollingFlatFileTraceListener although the starting pattern in the config file is not coming into effect. If you could advise on this as well, that would be great.
May 23, 2007 at 9:55 PM


Can one of you guys post a sample config file which will log exceptions to the database. Maybe it is too much trouble to go through mine but if yours works, then I will just tweak it for my circumstances

Thanks
-RV
May 24, 2007 at 2:40 PM
I don't think it is a configuration problem if you are getting something logged to the database.

What do you mean by see? Maybe the tool you are using to view the column data only displays some of the data. You probably need to query the data and display it in a medium where you know it will show all the column information.

The FormattedMessage Column is an nText field in the Log Table so we are not bumping up against column size limits. The Message Column only holds 1500 characters, so if messages get big that may need to be bumped up.

I would verify again that perhaps all the data is there but your viewing tool is just not showing it all.

Regards,

Dave

__________________________________

David Hayden
Microsoft MVP C#