In log4net, it is possible to choose between loading the configuration from the app.config
, or from an arbitrary xml file.
Is it possible to load the configuration for System.Diagnostics.TraceSource
from an arbitrary xml file?
System.Diagnostics classes look only at application configuration file. E.g. remarks section of SourceSwitch says:
To configure a SourceSwitch, edit the configuration file that corresponds to the name of your application.
If you will look into code, you'll see that internally these classes use static DiagnosticConfiguration
class which simply gets system.diagonostics
configuration section from current app.config
BUT you can move system.diagonostics
configuratin section to separate xml file. Just specify name of file where section will be defined:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics configSource="diagnostics.xml"/>
</configuration>
diagnostics.xml
<system.diagnostics>
<sources>
<source name="foo" switchName="bar"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="console"/>
</listeners>
</source>
</sources>
<switches>
<add name="bar" value="Warning"/>
</switches>
<sharedListeners>
<add name="console"
type="System.Diagnostics.ConsoleTraceListener" initializeData="false"/>
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="console"/>
</listeners>
</trace>
</system.diagnostics>