Custom Trace Listener: communicate with objects outsides

Topics: Logging Application Block
Dec 13, 2008 at 3:57 PM

I need to create my own trace listener it sends the formatted messages via an raised event to a receiver.
Definition is:

        public delegate void SendLogEntry (object sender, DataEventArgs<string> args);
        public static event SendLogEntry OnSendLogEntry;

This works so far, the receiver is class who manages the log-entries because of some filtering for UI and such stuff.

So, why I am here?
Is there a better way as raising an static declared event? It would be cool to inject a service, who provides a method thats called within CustomTraceListener.Trace(...). But EntLib creates the objects by itself, I get an error while providing something other than default parameterless ctor...

Have I miss something? Is there a better way the communicate with (already existing) objects outside the tracelistener? Another short question: whats is he shorted way to access the tracelistener from outer code?

Greetings, schue
Dec 14, 2008 at 3:56 AM
Have you already tried using PolicyInjection?

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Jan 9, 2009 at 6:03 AM
Actually not, I must confess that PolicyInjection wasnt on my radar until now.
By practical considerations I still use the 'event-pattern'.
Perhaps you can give me a catchword within PolicyInjection scope to search for answers?

Jan 9, 2009 at 6:30 AM
You would configure a policy and add a LogCallHandler and at least a matching rule that you prefer.  The documentation would give you a lot information.  

Policy Injection Application Block -> Key Scenarios - > Configuring and Using Pipeline Handlers -> LoggingHandler
Policy Injection Application Block -> Key Scenarios - > Configuring and Using Matching Rules 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.