Loading configuration for System.Diagnostics.TraceSource from XML file

In log4net, you can choose to load the configuration from app.configor from an arbitrary xml file.

Is it possible to load the configuration for System.Diagnostics.TraceSourcefrom an arbitrary xml file?

+4
source share
1 answer

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>
+4

Source: https://habr.com/ru/post/1526957/


All Articles