"Exception has been thrown by the target of an invocation" - when writing log through enterprise library logging 5.0

Topics: Exception Handling Application Block, Logging Application Block
Nov 3, 2011 at 5:55 AM
Edited Nov 3, 2011 at 6:04 AM

hi team,

when writing log through enterprise library 5.0 ,i get the following error "exception has been thrown by the target of an invocation".

But the same error is not happening when i am using "Enterprise Library 4.0" .Please clarify..

My sample code :

catch (FaultException fe)
            {
                //This code is temporary till services return proper codes or
                //specific fault exception for e.g CaseNotFoundException.
                if (fe.Message.Contains("case not available in IRIS") == true)
                {
                    _caseInfo = null;
                }
                else
                {                   
                    LogEntry _logentry = new LogEntry();
                            _logentry.Categories.Add(ItemNames.ServiceError);
                                //_logentry.Priority = 2;
                                //_logentry.EventId = 4000;
                            _logentry.Severity = System.Diagnostics.TraceEventType.Error;
                            _logentry.Title = ItemNames.LogTitle;
                            _logentry.Message = fe.GetType().Name + " - " + fe.Message;

                            if (Logger.IsLoggingEnabled())
                            {
                                Logger.Write(_logentry);                              
                            }
                    throw fe;
                }
            }

 

App.config:

  <loggingConfiguration name="Logging Application Block" tracingEnabled="false"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">


    <listeners>
      <add name="FlatFileTraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="c:\IRISTrace.log" header="======================================================================="
        footer="======================================================================="
        formatter="Text Formatter" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack"
        filter="All" />


      <add name="Formatted EventLog TraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="LC.IRIS.UI.Shell" formatter="Text Formatter" log="Application"
        machineName="" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack"
        filter="All" />


    </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: {timestamp(local)}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;)}"
        name="Text Formatter" />


    </formatters>
    <logFilters>

<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        enabled="true" name="LogEnabled Filter" />


    </logFilters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="FlatFileTraceListener" />
        </listeners>
      </add>
      <add switchValue="All" name="ServiceErrors">
        <listeners>
          <add name="FlatFileTraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

After further analyzation through event viewer, i got the following more cleaner error.

 

Log Name:      Application
Source:        System.ServiceModel 3.0.0.0
Date:          03-11-2011 09:48:57
Event ID:      8
Task Category: Message Logging
Level:         Information
Keywords:      Classic
Description:
Message Logging has been turned on. Sensitive information may be logged in the clear, even if it was encrypted on the wire: for example, message bodies.
 Process Name: IDRIS-Dev.vshost
 Process ID: 5152

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="System.ServiceModel 3.0.0.0" />
    <EventID Qualifiers="49154">8</EventID>
    <Level>4</Level>
    <Task>7</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2011-11-03T04:18:57.000000000Z" />
    <EventRecordID>33141</EventRecordID>
    <Channel>Application</Channel>
    <Security UserID="S-1-5-21-2142520273-2711432269-1748744671-1249" />
  </System>
  <EventData>
    <Data>IDRIS-Dev.vshost</Data>
    <Data>5152</Data>
  </EventData>
</Event>

 

 

Thanks

Ulaga

Nov 3, 2011 at 6:33 AM

The code and configuration look OK.  Can you post the full exception information including stacktrace?

Thanks.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Nov 11, 2011 at 10:00 AM

Hi randy,

Thanks for your response J

Actually i identify the problem, the error is happening only when i used

"Microsoft.Practices.CompositeUI.EventBroker.EventTopicException" ,  if i comment the below exception policy  in app.config and execute my logging then everything is working fine for me.

<exceptionHandling>
    <exceptionPolicies>
      <add name="Default Policy">
        <exceptionTypes>
          <add name="AuthenticationException" type="System.Security.Authentication.AuthenticationException, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           postHandlingAction="None">
            <exceptionHandlers>
              <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               logCategory="General" eventId="100" severity="Information" title="Enterprise Library Exception Handling"
               formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               priority="0" />
            </exceptionHandlers>
          </add>
          <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           postHandlingAction="NotifyRethrow">
            <exceptionHandlers>
              <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
               formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               priority="0" />
            </exceptionHandlers>
          </add>
          <add type="Microsoft.Practices.CompositeUI.EventBroker.EventTopicException, Microsoft.Practices.CompositeUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          postHandlingAction="NotifyRethrow" name="EventTopicException">
            <exceptionHandlers>
              <add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="LC.IDRIS.UI.Infrastructure.Library.EntLib.EventTopicExceptionFormatter, LC.IDRIS.UI.Infrastructure.Library"
                priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Logging Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

 

 

This is my EventVwr trace information :

 

Log Name:      Application

Source:        System.ServiceModel 3.0.0.0

Date:          11-11-2011 16:20:05

Event ID:      8

Task Category: Message Logging

Level:         Information

Keywords:      Classic

Description:

Message Logging has been turned on. Sensitive information may be logged in the clear, even if it was encrypted on the wire: for example, message bodies.

 

 Process Name: IDRIS-Dev

 

 Process ID: 5144

 

Thanks

Ulaga