config file vs runtime

Topics: Logging Application Block
Jan 25, 2008 at 5:51 AM
Hi

i am trying to configure el.logging at runtime rather than using the config file as i do not know the amount of differnt trace files required before hand. these files should be created from the database per "client".
have managed to create create el.logging at runtime but have seen a huge differece in cpu usage when running the "runtime version" vs the "config version" of my application.
below is my code and config. any help will be appreciated.

thanks

el.LogEntry logentry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry();
logentry.Message = "Starting Application";
logentry.Severity = System.Diagnostics.TraceEventType.Information;


List<System.Diagnostics.TraceListener> tracelisteners = new List<System.Diagnostics.TraceListener>();
el.TraceListeners.FlatFileTraceListener flattracelistener = new Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener("test.log", "header", "footer", new el.Formatters.TextFormatter("Message: {message}"));
tracelisteners.Add(flattracelistener );

el.LogSource errorsource = new Microsoft.Practices.EnterpriseLibrary.Logging.LogSource("error", System.Diagnostics.SourceLevels.All);
errorsource.Listeners.Add(flattracelistener);

Dictionary<string, el.LogSource> logsources = new Dictionary<string, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource>();
el.LogSource logsource = new Microsoft.Practices.EnterpriseLibrary.Logging.LogSource("General", System.Diagnostics.SourceLevels.All);
logsource.Listeners.Add(flattracelistener);
logsources.Add("General", logsource);

el.LogWriter l2 = new Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(new el.Filters.ILogFilter0, logsources, errorsource, "General");


<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
</configSections>
<loggingConfiguration tracingEnabled="true" defaultCategory="General">


<formatters>
<add
name="Text Formatter"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
template="Message: {message}"/>
</formatters>

<logFilters>
</logFilters>

<categorySources>
<add
name="General"
switchValue="All">
<listeners>
<add name="Flat File Destination" />
</listeners>
</add>
</categorySources>

<specialSources>
<errors name="errors" switchValue="All">
<listeners>
<add name="Flat File Destination" />
</listeners>
</errors>
</specialSources>

<listeners>
<add name="Flat File Destination"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
fileName ="working.log"
header ="header"
footer ="footer"
formatter="Text Formatter"
/>

</listeners>

</loggingConfiguration>