Exception Handling with Logging

Jan 8, 2009 at 6:11 PM

Codeplex,

This one should be very easy for someone out there with a trained eye. I'm attempting to log errors to a SQL database using EntLib 4.0. When I call ExceptionPolicy.HandleException() there are no errors thrown, yet the database is empty. The connection string is good, nothing shows up in profiling SQL Server, and unknown categories should be logged as well. I ran the scripts on the database located in the /scripts folder of the EntLib4 folder, and I've been scratching my head for too long and it's time to ask what's going on.

Here is my config file:

 

<?

xml version="1.0" encoding="utf-8"?>

 

<

configuration>

 

<

configSections>

 

<

section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 

<

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 

 

</configSections>

 

<

loggingConfiguration name="Logging Application Block" tracingEnabled="true"

 

 

defaultCategory="Regence.QuotingProcess.*" logWarningsWhenNoCategoriesMatch="true">

 

<

listeners>

 

<

add databaseInstanceName="Logging" writeLogStoredProcName="WriteLog"

 

 

addCategoryStoredProcName="AddCategory" formatter="Text Formatter"

 

 

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Database Trace Listener" />

 

</

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, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

name="Text Formatter" />

 

</

formatters>

 

<

categorySources>

 

<

add switchValue="All" name="Regence.QuotingProcess.Services">

 

<

listeners>

 

<

add name="Database Trace Listener" />

 

</

listeners>

 

</

add>

 

<

add switchValue="All" name="Regence.QuotingProcess.*">

 

<

listeners>

 

<

add name="Database Trace Listener" />

 

</

listeners>

 

</

add>

 

</

categorySources>

 

<

specialSources>

 

<

allEvents switchValue="All" name="All Events">

 

<

listeners>

 

<

add name="Database Trace Listener" />

 

</

listeners>

 

</

allEvents>

 

<

notProcessed switchValue="All" name="Unprocessed Category">

 

<

listeners>

 

<

add name="Database Trace Listener" />

 

</

listeners>

 

</

notProcessed>

 

<

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

<

listeners>

 

<

add name="Database Trace Listener" />

 

</

listeners>

 

</

errors>

 

</

specialSources>

 

</

loggingConfiguration>

 

<

exceptionHandling>

 

<

exceptionPolicies>

 

<

add name="GenericPolicy">

 

<

exceptionTypes>

 

<

add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

 

 

 

 

postHandlingAction="NotifyRethrow" name="Exception">

 

<

exceptionHandlers>

 

<

add logCategory="Regence.QuotingProcess.*" eventId="100" severity="Error" title="Qpex Service Layer Exception - General Error"

 

 

 

 

formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

name="Logging Handler" />

 

</

exceptionHandlers>

 

</

add>

 

</

exceptionTypes>

 

</

add>

 

<

add name="ServicePolicy">

 

<

exceptionTypes>

 

<

add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

 

 

 

 

postHandlingAction="None" name="Exception">

 

<

exceptionHandlers>

 

<

add logCategory="Regence.QuotingProcess.Services" eventId="100" severity="Error" title="Qpex Service Layer Exception - Known Exception"

 

 

 

 

formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

name="Logging Handler" />

 

</

exceptionHandlers>

 

</

add>

 

</

exceptionTypes>

 

</

add>

 

</

exceptionPolicies>

 

</

exceptionHandling>

 

<

dataConfiguration defaultDatabase="QPEX" />

 

<

connectionStrings>

 

<

add name="QPEX" connectionString="[valid connection string]"

 

 

providerName="System.Data.SqlClient" />

 

</

connectionStrings>

 

<

appSettings>

 

<!--

 stuff -->

 

</

appSettings>

 

 

 

 

</

configuration>


TIA,

brenton.Unger()

 

Jan 8, 2009 at 7:49 PM
As I suspected. This was something very easy that I was missing. This was a permissions issue with the stored procedures that were created.