Can't find class using 'Type Selector' when attempting to select a Costum TraceListener

Topics: Logging Application Block
Feb 22, 2009 at 9:37 AM
Hi,

I am trying to create a custom TraceListener. (exactly like in the example)



namespace CA {

[ConfigurationElementType(typeof(CustomTraceListenerData))]
public class DebugTraceListener : CustomTraceListener {

    public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data) {
        if (data is LogEntry && this.Formatter != null) {
            this.WriteLine(this.Formatter.Format(data as LogEntry));
        } else {
            this.WriteLine(data.ToString());
        }
    }

    public override void Write(string message) {
        Trace.Write(message);
    }

    public override void WriteLine(string message) {
        Trace.WriteLine(message);
    }
}

}



When I try to select the type using the Type Selector I don't see the class. All I see is <undefined> in the upper window and "Classes that inherit....." and below "Assemblies" in the lower window. I tried to manually set the type to "CA.DebugTraceListener" but I get BuildFailedException when executing the program.

here is the app.config:



<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="CA.DebugTraceListener"
        name="Custom Trace Listener" initializeData="" />
    </listeners>
    <formatters>
      <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=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General" />
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Custom Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings" />
    </specialSources>
  </loggingConfiguration>
</configuration>



Can anyone recommend a solution ? The program has a single cs.

Gilad

Feb 23, 2009 at 2:55 AM
You should click Load From File in the type selector and browse for projectname.exe if your project is an executable or projectname.dll if it is a classlibrary from the bin -> Debug folder of your project.


Sarah Urmeneta
Global Technology & Solutions
Avande, Inc.
entlib.support@avanade.com