Issues Logging to a Database using the Exception Handling Block

Topics: Exception Handling Application Block, Logging Application Block
Aug 19, 2008 at 9:26 PM
Edited Aug 19, 2008 at 9:31 PM

Listed below is the code in my catch block:
catch(Exception ex)
{
  ExceptionPolicy.HandleException(ex, "LogOnlyPolicy");
}



Listed below is my config file. I am not able to get the logging to a database working. I can log to a flat file but when I try to use the database trace listner, while I get no errors I see no entries in the database either. somebody please help. I have spent a lot of time researching and followed the exact steps but am unable to solve the issue.

 

<

configuration>

 

 

<

configSections>

 

 

<

section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

 

<

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

 

 

<

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />

 

 

</

configSections>

 

 

<

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

 

 

 

defaultCategory="" 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=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

name="Database Destination" />

 

 

<

add fileName="C:\Logifiles\trace.log" header="----------------------------------------"

 

 

footer="----------------------------------------" formatter=""

 

 

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

name="FlatFile Destination" />

 

 </

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=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

name="Text Formatter" />

 

 

</

formatters>

 

 

<

categorySources>

 

 

<

add switchValue="All" name="DatabaseLog">

 

 

<

listeners>

 

 

<

add name="Database Destination" />

 

 

</

listeners>

 

 

</

add>

 

 

<

add switchValue="All" name="Tracing">

 

 

<

listeners>

 

 

<

add name="FlatFile Destination" />

 

 

</

listeners>

 

 

</

add>

 

 

</

categorySources>

 

 

<

specialSources>

 

 

<

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

 

 

<

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

 

 

<

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

 

 

</

specialSources>

 

 

</

loggingConfiguration>

 

 

<

exceptionHandling>

 

 

<

exceptionPolicies>

 

 

<

add name="LogOnlyPolicy">

 

 

<

exceptionTypes>

 

 

<

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

 

 

postHandlingAction="None" name="Exception">

 

 

<

exceptionHandlers>

 

 

<

add logCategory="DatabaseLog" eventId="100" severity="Error"

 

 

title="Legal Career Site" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

 

priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

 

 

name="Logging Handler" />

 

 

</

exceptionHandlers>

 

 

</

add>

 

 

</

exceptionTypes>

 

 

</

add>

 

 

</

exceptionPolicies>

 

 

</

exceptionHandling>

 

 

<

dataConfiguration defaultDatabase="Logging" />

 

 

<

connectionStrings>

 

 

<

add name="Logging" connectionString="Data Source=(local);Initial Catalog=logging;Persist Security Info=True;User ID=logging;Password=logging"

 

 

providerName="System.Data.SqlClient" />

 

 

</

connectionStrings>

 

 

 

 

 

 

 

Aug 28, 2008 at 3:21 AM
Hi All!!
I noticed the same problem today, but I have more details:

1. If to your non working logging policy you add a second handler like a Replace Handler it works...
2. If you use the PIAB and Call Handler to decorate your class or method, like this

[

ExceptionCallHandler("LogOnlyPolicy")]

 

it will work as it must, (of course you must put out your code of the try/catch) and with the same non working Policy invoked by the ExceptionPolicy...

3. No attemp to log to the database is done, the SQL Profiler for my logging database shows it...

Please if someone more have this issue or make the ExceptionPolicy with Logging Handlers works tell us!!

I guess this must be reported as issue...