How to get acces into switch declared in App.config?

126 views Asked by At

This is a snippet from my App.config :

 system.diagnostics
    switches
      add name="Logowanie" value="Verbose"
   /switches
 /system.diagnostics

How can I make TraceSwitch in my C# code that will be connected with this one "Logowanie" from App.config? I want in my code to be able to write something like :

if (myTraceSwitch.TraceVerbose)
{
    ....
}

To be honest I made one just with :

TraceSwitch myTraceSwitch = new TraceSwitch("Logowanie", "This is my switch");

as you can see, just with the same name like in App.config but I think it doesnt work :/

1

There are 1 answers

0
Ronald Abellano On

The switch you declared in your App.config has to be instantiated in your app with the same switch name, then the app will get the properties of that switch that were set in your App.config.