0

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 :/

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
CSharpBeginner
  • 1,625
  • 5
  • 22
  • 36
  • `I think it doesnt work` why not just try it first? don't think because you are the asker and you should try yourself first, only answers can say *I think...* because in some cases they don't really have condition to test the code... – King King Dec 07 '13 at 11:01
  • I think id doesn't work because I did it, set Verbose in App.config, did if(myswitch.TraceVerbose) and nothing happen at all :D – CSharpBeginner Dec 07 '13 at 11:30

1 Answers1

0

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.

Ronald Abellano
  • 774
  • 10
  • 34