In my app.config I want to set 3 tracing levels (switches?): verbose, warning and none. In the debug version of the code, I want the verbose switch to be active, in the release I want warning. In special cases my application users can modify the config file to disable all traces.
I want debug traces to output on the console, while release traces only to a log file.
I',ve written the following:
[...]
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="debug" switchName="debug">
<listeners>
<add name="FileLog"/>
<add name="console"/>
</listeners>
</source>
<source name="release" switchName="release">
<listeners>
<add name="FileLog"/>
</listeners>
</source>
<source name="silent" switchName="none">
<listeners/>
</source>
</sources>
<switches>
<add name="debug" value="Verbose"/>
<add name="release" value="Warning"/>
<add name="none" value="Off"/>
</switches>
<!--<sharedListeners>
<add name="FileLog" type="System.Diagnostics.TextWriterTraceListener" traceOutputOptions="DateTime" initializeData="felix.log"/>
<add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false" />
</sharedListeners>-->
<trace autoflush="false" indentsize="4">
<listeners>
<add name="FileLog" type="System.Diagnostics.TextWriterTraceListener" traceOutputOptions="DateTime" initializeData="felix.log"/>
<add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false"/>
<remove name="Default"/>
</listeners>
</trace>
</system.diagnostics>
[...]
Then in code I call trace like this:
Public Shared Sub HandleException(ByVal ex As Exception)
Trace.WriteLine(ex.Message, "Error")
[...]
There's something I'm missing I think. How do I say to the Trace method the right switch to use?? How can my application users change the config file to allow for tracing or disable it?
Thanks.