Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change trace switch level via app.config

I have app that configures its trace source as follows:

        var traceSource = new TraceSource("MyTraceSource");
        traceSource.Switch = new SourceSwitch("MyTraceSwitch") { **Level = SourceLevels.Information** };

        var traceListener = new TextWriterTraceListener(logFilePath);
        traceListener.TraceOutputOptions = TraceOptions.DateTime;

        traceSource.Listeners.Clear();
        traceSource.Listeners.Add(traceListener);

        Trace.AutoFlush = true;

The app always uses this trace source to trace events. Please note that SourceLevels.Information is hardcoded in trace switch. Now I need to change the trace switch level to Verbose. Is it possible to accomplish via app.config file? I tried many xml-configs but failed. Note I cannot change the source code only app.config.

like image 350
Ivan Ivanov Avatar asked Feb 15 '13 08:02

Ivan Ivanov


1 Answers

I'm not sure if you are searching for something like this, but I've used once the following xml configuration to: change the trace switch level to Verbose.(App-Config)

  <configuration>
        <system.diagnostics>
            <switches>
            <add name="AppTraceLevel" value="4" /> //4 = Verbose
            </switches>
            // Here would be the Trace Tag with the Listeners (not important for your question)
        </system.diagnostics>
    </configuration>

Maybe it helps

like image 185
eMi Avatar answered Sep 28 '22 03:09

eMi