Monday, February 26, 2007

logging application block 2.0 (LoggingSettings, ConfigurationManager, GetSection, TraceListener Information)

working on reading form this loggingconfiguration section was a bit tuff, I would to the properties collections for the tracelisteners, and still get stuck, not getting any info. Pair programming on it with a collegue from octo technologies, it was great that we came up with this solution. I propose the logging application block, work with it, and my collegue brings in his experience with reading configuration files. in this context, i'll talk about this as an gile technique later on, in another post.

the result is below, not much, but a modest, useful piece of code

retreiving the fileName of a flatfile tracelistener from the LoggingConfiguration Section of the configuration file.
This can be done in using the following function:


//recives The name of the trace listener, and property desired of this tracelistener
//example: string fileName = GetTraceListenerInfo("FLTraceListener1", "fileName");
private string GetTraceListenerInfo(string name, string property)
{

//LoggingSettings is the class representing the collection
LoggingSettings ls = ConfigurationManager.GetSection("loggingConfiguration") as LoggingSettings;

//getting into the trace listeners collection
if (ls.TraceListeners != null)
{
TraceListenerData tld = ls.TraceListeners.Get(name);
PropertyInformation pi = tld.ElementInformation.Properties[property];

//get the property value
return pi.Value.ToString();
}
else
{
return string.Empty;
}
}


Comments Welcome!

No comments: