The System.Diagnostics classes only look at the application configuration file. For example. notes section SourceSwitch says:
To configure SourceSwitch, edit the configuration file that matches the name of your application.
, , DiagnosticConfiguration, system.diagonostics app.config
system.diagonostics configuratin xml. , :
<?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>