Fetching the TraceListener name based on Category

Topics: Logging Application Block
Jul 7, 2009 at 11:30 AM

Hi,

I would like to know if there is a way to fetch the name of the TraceListener associated with a Category programmatically. If yes, how?

Thanks in advance for your help!

-Bhaskar.

Jul 7, 2009 at 11:57 AM
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
LoggingSettings loggingSettings = (LoggingSettings)config.GetSection(LoggingSettings.SectionName);            
TraceSourceData traceSource = loggingSettings.TraceSources.Get("General");
foreach (TraceListenerReferenceData traceListenerReferenceData in traceSource.TraceListeners)
{
        TraceListenerData traceListener = loggingSettings.TraceListeners.Get(traceListenerReferenceData.Name);
}

Each item in the traceSource.TraceListeners is of type TraceListenerReferenceData, it only holds the name of the tracelistener so I used it to get the tracelisteners associated to the "General" category.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jul 7, 2009 at 12:38 PM

Hi,

Thanks for your reply. I make use of the Rolling Flat File. Is the code above good for Rolling Flat file as well?

-Bhaskar

Jul 7, 2009 at 12:41 PM

Yes, the RollingFlatFileTraceListenerData also inherits from the TraceListenerData.  If you only want to get the RollingFlatFileTraceListener, just check if(traceListener.GetType() == typeof(RollingFlatFileTraceListenerData))

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jul 7, 2009 at 1:21 PM

Hi Sarah,

Thanks for your replies. It really answered my questions and helped me move ahead. This forum rules!

Cheers,

-Bhaskar.