Custom Trace Listener Error

Topics: Logging Application Block
Nov 8, 2007 at 1:20 PM
I am trying to create a custom trace listener using the configuration tool. I click on Type and then drill down to my class library project named "TestProject". In TestProject, I have a class named faCustomTraceListener. This class inherits from CustomTraceListener. But I get this error when I browse to TestProject in the Type field on the configuration tool:

There were no types found in the assembly TestProject that implement or inherit from the base type Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.CustomTraceListener.

I am brand new to EL 3.1 and Logging in general. I am clueless here on what I did wrong. Any Help would be apprecitated.

Thanks,
Bob
Nov 9, 2007 at 7:14 PM
Hi,

You need to add the ConfigurationElementType, specifying the CustomTraceListenerData type.

However, it looks like you hit a problem with the configuration tool. For most custom providers, you would need to add the ConfigurationElementType to let the configuration serialization code deserialize configuration. However, since existing TraceListeners may not have such an attribute, a different mechanism is used for trace listeners so the attribute is not required. Unfortunately, the configuration tool node, which represents the configuration at design time, seems to rely on the attribute for filtering.

Regards,
Fernando
Nov 12, 2007 at 1:18 PM
Hey Fernando,

I do have ConfigurationElementType specifying the CustomTraceListenerData. Of course maybe I specified this incorrectly. Here is the code for my class faCustomTraceListener.vb:

Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration
Imports Microsoft.Practices.EnterpriseLibrary.Logging.Configuration
Imports Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData
Imports Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners

<ConfigurationElementType(GetType(CustomTraceListenerData))> _
Public Class faCustomTraceListener
Inherits CustomTraceListener

Public Overloads Overrides Sub Write(ByVal message As String)

End Sub

Public Overloads Overrides Sub WriteLine(ByVal message As String)

End Sub

End Class

Is this code incorrect?

Thanks,
Bob
Nov 13, 2007 at 10:24 AM
Edited Nov 13, 2007 at 10:26 AM
Hi Bob,

The code looks fine. This is a similar example that I wrote in C# (and it worked as expected)

using System;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;

namespace CustomTraceListenerRepro
{
[ConfigurationElementType(typeof(CustomTraceListenerData))]
public class MyCustomTraceListener : CustomTraceListener
{
public static List<string> messages = new List<string>();

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

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


Is it possible your projects are linking a version of the entlib binaries that is not the version expected by the configuration tool? Eg, you are referencing the source code projects but use the configuration tool from the start menu shortcut.

Regards,
Fernando
Nov 13, 2007 at 12:50 PM
Hi again Fernando,

You mentioned that I may have a versioning problem. This is very possible. What is the best way to fix this? Would I be better off to remove EL 3.1 and start over? I have nothing in production yet so it's no big deal. Also, Ihow do I guard against doing this in the future? Why does Microsoft download 2 copies of the same thing with different versions?

Thanks,
Bob
Nov 13, 2007 at 1:18 PM
Hi Bob,

EntLib 3.1 ships with binaries signed by Microsoft and the source code. Since you cannot create binaries with Microsoft's key, any references to the source code projects or binaries created with them will necessarily have a different identity. This isn't an issue per se, but can be a source of confusion.

To deal with this situation you need to decide on which version you want to use and stick with it; using the binaries is usually easier to handle. In the repro I did, I referenced the signed binaries.

Fernando