Exception Logging is not working in production

Topics: Exception Handling Application Block, Logging Application Block
Sep 6, 2007 at 6:46 AM
I am using Enterprise Library 3.1 Exception Handling Application block for logging exceptions to a flat file using Flat File Trace Listener. In my local system, its logging the exception properly but when I moved to production, its not working. I tried to give permissions to the folder of the file path. But its not working. Please help.
Here i am providing the web.config code:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="Trace" logWarningsWhenNoCategoriesMatch="true">
<add fileName="D:\trace.log" header="----------------------------------------"
footer="----------------------------------------" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="Callstack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="FlatFile TraceListener" />
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Formatted EventLog TraceListener" />
<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=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter" />
<add switchValue="All" name="General">
<add name="Formatted EventLog TraceListener" />
<add switchValue="All" name="Trace">
<add name="FlatFile TraceListener" />
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<add name="Formatted EventLog TraceListener" />
<add name="SPS Exception Policy">
<add type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception">
<add logCategory="Trace" eventId="100" severity="Error" title="SPS Exception Logging"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Logging Handler" />
Sep 6, 2007 at 1:38 PM

What kind of trust setting are you using for your application?

Sep 7, 2007 at 11:41 AM
I am using Default trust for my application.

fsimonazzi wrote:

What kind of trust setting are you using for your application?


Sep 7, 2007 at 3:06 PM
Does the windows identity you use to run your application have permissions to write to the flat file?
Btw, if you enable instrumentation you should see entries in the event log describing the failure.

Oct 11, 2007 at 10:44 PM
Hi Fernando,

I am using the Flat File Trace Listener to write to a text file, and i am specifying a certain folder to write the text file to, i am explicitly denying all permissions on that folder to the identity that is running the application because i want the access denied exception returned to me so that i can handle it in case this happens in production, but even with the permissions denied on the folder the application that does the logging will run and not return any errors and obviously since i denied permissions on the folder it does not write any log text files. Do you know why the Logging Application Block does not return any errors even when permissions are denied to writing to that folder? Thanks for any help that you can provide.

Oct 12, 2007 at 2:53 PM
Hi Devang,

The Logging block will not expose logging errors to the client application; instead will attempt to log the error to the location specified in the "errors" special source, falling back to the standard instrumentation mechanisms (perf counters, wmi and event log).

This is by design, to make logging as simple as possible for the application. The application logic is not expected to handle a logging issue; instead the block should be properly configured and the minimal permissions to access fallback instrumentation must be granted.