trace listeners

  • Thread starter Thread starter Keith Langer
  • Start date Start date
K

Keith Langer

I'd like to know if there is a way to dynamically control which trace
listeners get used for logging. For instance, I might want to log in
general to the event log, the console, and a file, but I might want to
log specific errors to only one or two of those sources. The only way
I can see to do that is to remove the listener I don't want to log to,
log the message, and then add the listener. Is there another way?

Also, can a trace listener be set up for database logging or HTTP
posting?

thanks,
Keith
 
Your best bet is to create custom Listeners (not difficult to do at all) and
add those instead of the default/built-in Listeners.
In fact, you can simply create a Listener that acts as a filter and
delegates the log messages to an existing Listener class if appropriate.

-Rob Teixeira [MVP]
 
Rob,

How would you pass the filter to the custom listener? It looks like it
only takes one string argument (write, writeline, etc.). Is there a way
to pass it an object?

Keith
 
Try creating config settings. Then, you can set whatever you like in config
files and change settings without recompiling.

-Rob Teixeira [MVP]
 
Rob,

Is there someplace that has examples of a custom listener? For instance I
would want to put the date/time stamp and then follow it by the log message.

Thanks
 
Back
Top