Del via


Linking Custom Config File to Machine Config File

There is configSource attribute with help of which content of the Machine.config file can be redirected to the custom config file.

 

Below is the sample

 

<system.diagnostics configSource="GlobalDiagnostics.config">

</system.diagnostics>

 

For the system diganostic section in machine.config file a seperate  config file is been created, file name is GlobalDiagnostic.config. Global diagnostic file can then contain the diagnostics related configurations. Below is the sample content of the  

 

<?xml version="1.0" encoding="utf-8"?>

<system.diagnostics>

  <sharedListeners>

    <add name="CustomTraceListener" type="Instrumentation.Framework.CustomTraceListener, Instrumentation.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b40e65bd72b277e3" traceOutputOptions="LogicalOperationStack" />

  </sharedListeners>

  <switches>

    <add name="Debug" value="Verbose,ActivityTracing" />

    <add name="TraceSourceSwitch" value="All" />

  </switches>

  <trace autoflush="true" indentsize="4" />

  <sources>

    <source name="TestEventSource" switchType="System.Diagnostics.SourceSwitch" switchName=" TraceSourceSwitch ">

      <listeners>

        <remove name="Default" />

        <add name="CustomTraceListener" />

      </listeners>

    </source>

  </sources>

</system.diagnostics>

 

But this has limitation that config file must be in the same or sub folder, the path has to be below the current path of the machine config file.