views:

234

answers:

1

I'm having some problems configuring the exception handler the way I want it. What I want is to log the warnings and above in one file (errors.txt) and everything (including the warnings and errors) in a file named all.txt.

The problem is that I can't get the errors to be logged in all.txt, I only get an entry in errors.txt and a separate file named {guid}all.txt with the error inside.

Can anyone see what I'm doing wrong and help me on the right track?

<exceptionHandling>  <exceptionPolicies>
<add name="Default">
  <exceptionTypes>
    <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        postHandlingAction="None">
      <exceptionHandlers>
        <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
            logCategory="Errors" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
            formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="0" />
      </exceptionHandlers>
    </add>
  </exceptionTypes>
</add>  </exceptionPolicies></exceptionHandling>

<loggingConfiguration name="" tracingEnabled="false" defaultCategory="All" evertImpersonation="false">  <listeners>
<add name="All Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    fileName="Logs\All.txt" footer="" formatter="All Formatter"
    header="" rollInterval="Day" maxArchivedFiles="7" />
<add name="Errors Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    fileName="Logs\Errors.txt" formatter="Errors formatter" rollInterval="Day"
    maxArchivedFiles="7" filter="Warning" />  </listeners>  <formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    template="{timestamp(local:dd.MM.yyyy hh:mm:ss.fff)} - {severity} - {message}"
    name="All Formatter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    template="Timestamp: {timestamp(local:dd.MM.yyyy hh:mm:ss.fff)}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
    name="Errors formatter" />  </formatters>  <logFilters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    enabled="true" name="Logging Enabled Filter" />  </logFilters>  <categorySources>
<add switchValue="All" name="All">
  <listeners>
    <add name="All Listener" />
  </listeners>
</add>
<add switchValue="Warning" name="Errors">
  <listeners>
    <add name="Errors Listener" />
    <add name="All Listener" />
  </listeners>
</add>  </categorySources>  <specialSources>
<allEvents switchValue="Off" name="All Events" />
<notProcessed switchValue="Off" name="Unprocessed Category" />
<errors switchValue="Off" name="Logging Errors &amp; Warnings" />  </specialSources></loggingConfiguration>
A: 

Don't use Enterprise Library. I'd recommend using ELMAH which provides a much richer error handling experience and is substantially easier to configure...

Jason