Exception When Loading the Configuration for Custom Trace Listner

Topics: Enterprise Library Core, Logging Application Block
Aug 31, 2009 at 10:41 PM

Hi There,

I have implemented a custom trace listner which is supposed to call the WCF service to log the exceptions. Here is how I did it...

namespace ChoiceAdministrators.Opportunity.Utility.ExceptionManager
{
    [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class ExceptionManagerTraceListner : CustomTraceListener
    {
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {

.................

}

..........OTHER CODE TO OVERRIDE Write(string message) and WriteLine(string message)

}

Here is how my configuration file looks like....

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

<listeners>
      <add
       name="Log To Service"
       formatter="Text Formatter"
       listenerDataType="ChoiceAdministrators.Opportunity.Utility.ExceptionManager.ExceptionManagerTraceListner, Utility.ExceptionManager"
       machineName="."
       source="TESTCAT"
       type="ChoiceAdministrators.Opportunity.Utility.ExceptionManager.ExceptionManagerTraceListner, Utility.ExceptionManager" />
  
</listeners>

<add
    name="TESTCAT"
    switchValue="All">
        <listeners>
          <add name="Log To Service" />
        </listeners>

</add>

 I get the following exception when I call the Logger.Write(logEnty)

An error occurred creating the configuration section handler for loggingConfiguration: Unable to cast object of type 'ChoiceAdministrators.Opportunity.Utility.ExceptionManager.ExceptionManagerTraceListner' to type 'Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.TraceListenerData'. (C:\All Code\LoggingTest\LoggingTest\bin\Debug\LoggingTest.vshost.exe.Config line 8)

 

 

Aug 31, 2009 at 10:56 PM

Thanks for looking at this... I have found the answer. My Listner Configuration is not correct. Corrected it to the below and it worked.

    <listeners>
      <add
       name="Log To Service"
       formatter="Text Formatter"
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
       machineName="."
       source="TESTCAT"
       type="ChoiceAdministrators.Opportunity.Utility.ExceptionManager.ExceptionManagerTraceListner, Utility.ExceptionManager" />
  
    </listeners>