Textformatter error template

Topics: Exception Handling Application Block, Logging Application Block
Feb 5, 2014 at 10:46 AM
I have this configuration in my application, it work correctly, however textformatter is not applied. My log file return more information.

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Error">
<listeners>
  <add name="EscrituraFichero" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="c:\data.log" footer="" formatter="Text Formatter"
    header="" rollInterval="Day" rollSizeKB="120" timeStampPattern="yyyyMMdd"
    traceOutputOptions="Timestamp" />
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      template="{timestamp}: {category}: {severity}: {message}"

      name="Text Formatter" />
</formatters>




<logFilters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    maximumPriority="10" name="Priority Filter" />
</logFilters>
<categorySources>
  <add switchValue="All" name="Error">
    <listeners>
      <add name="EscrituraFichero" />
    </listeners>
  </add>
  <add switchValue="All" name="Informacion">
    <listeners>
      <add name="EscrituraFichero" />
    </listeners>
  </add>
  <add switchValue="All" name="ExcepcionError">
    <listeners>
      <add name="EscrituraFichero" />
    </listeners>
  </add>
</categorySources>
<specialSources>
  <allEvents switchValue="All" name="All Events" />
  <notProcessed switchValue="Error" name="Unprocessed Category">
    <listeners>
      <add name="EscrituraFichero" />
    </listeners>
  </notProcessed>
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="EscrituraFichero" />
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
  <add name="ErrorExcepcion">
    <exceptionTypes>
      <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.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=31bf3856ad364e35"
            logCategory="ExcepcionError" 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>
  <add name="ErrorExcepcionRethrow">
    <exceptionTypes>
      <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        postHandlingAction="NotifyRethrow">
        <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=31bf3856ad364e35"
            logCategory="ExcepcionError" eventId="200" 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>


This is file log:

05/02/2014 10:28:41: ExcepcionError: Error: HandlingInstanceID: aff3640d-a564-483c-b580-f8222d3eda12

An exception of type 'System.NotImplementedException' occurred and was caught.

02/05/2014 11:28:41
Type : System.NotImplementedException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : No se puede implementar el método o la operación.
Source : ConsoleApplication1
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ConsoleApplication1.ProcesarMensaje(System.String)
HResult : -2147467263
Stack Trace : en xxxxx en DynamicModule.ns.Wrapped_ISicocliService_53445af1176741d5ac7a1f81b1ed9302.<ProcesarMensaje_DelegateImplementation>__0(IMethodInvocation inputs, GetNextInterceptionBehaviorDelegate getNext)

Additional Info:xxxxx

However the textformatter is only {timestamp}: {category}: {severity}: {message}

¿why do it return more information?
Feb 5, 2014 at 1:08 PM
Before logging, the exception formatter, TextExceptionFormatter, is invoked by the Exception Handling Block and creates the Message property of the LogEntry. So the Logging Block is using your formatter but the Exception Handling Block has already formatted the Message property of the LogEntry (which is then logged).

The question you need to ask is what information (and format) you want to see when logging an exception. If you don't like the out of the box TextExceptionFormatter you can create a custom ExceptionFormatter and/or extend TextExceptionFormatter. See Adding a New Exception Formatter.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to