Injecting objects into the a CustomTraceListener

Topics: Logging Application Block
Jan 7, 2009 at 7:09 PM
I want to be able to reference an existing object from my CustomTraceLister, possibly through the UnityContainer.  It would have been nice if one add, as Dependency, the UnityContainer into
aCustomTraceListener's constructor like so:

 public LogViewerTraceListener(IUnityContainer container)
  { }


 public LogViewerTraceListener([Dependency]IUnityContainer container)
  { }

but upon doing so, I get the following error:

{"The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Log Policy]) failed: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]) failed: The type 'OCC600.Infrastructure.Library.OCCUtility.LogViewerTraceListener' specified for custom trace listener named 'Custom Listener' does not a default constructor, which is required when no InitData is specified in the configuration. (Strategy type ConfiguredObjectStrategy, index 2) (Strategy type ConfiguredObjectStrategy, index 2)"}

As I understand it, initData is of type 'System.String".  Unfortunately, such an argument cannot help me.

How do I go about doing this without affecting Entlib source code?



Jan 8, 2009 at 10:45 AM

What type of existing object do you want to reference from the existing CustomTraceListener? The customTraceListener must have a default constructor w/o param.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
Jan 8, 2009 at 1:57 PM
Existing object is a collection of LogEntries which will be bound to a datagrid.   All I am trying to do is display a category of log entries on a view, hence the need to this external reference.

Jan 9, 2009 at 2:55 AM
Edited Jan 9, 2009 at 2:56 AM
So I go about digging:

I tried accessing the CustomTraceLister from the back door using

System.Diagnostics.Trace.Listeners["Custom Trace Listener"]

and this gives me null.  So I figured the CustomTraceListener is not being added to the TraceListenerCollection.

Upon digging further, I see that custom trace listeners are being added to  the internal dictionary that is a member of the following struct:


Why is the custom trace listener being hidden?

Does anyone have an elegant solution of communicating to the custom trace listener?  
Jan 12, 2009 at 11:23 AM

If I understand it correctly, you want to access a collection of logEntries from a CustomTraceListener, and you are going to access it from another traceListerner? That means there are 2 CustomTraceListener? Why dont you just use the CustomTraceListener that has the collection of logEntries do the job?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.