Hello Peter,
As the MSDN documentation says,
(
http://msdn.microsoft.com/en-us/libr...aceswitch.aspx
)
"In your application, you can use the configured switch level by creating a
TraceSwitch with the same name"
So, we can just create a new instance of TraceSwitch that has the same name
as the one in configuration file to access the configured switch. For
example, I have the following part in the app.config,
------------------------------------------------
<system.diagnostics>
<switches>
<add name="mySwitch" value="1" />
</switches>
</system.diagnostics>
------------------------------------------------
Then in the application, to get the TraceSwitch level, I just need to use
the following codes,
------------------------------------------------
private static TraceSwitch appSwitch = new
TraceSwitch("mySwitch","Switch in config file");
static void Main(string[] args)
{
Console.WriteLine("Trace switch {0} configured as
{1}",appSwitch.DisplayName, appSwitch.Level.ToString());
}
------------------------------------------------
I have tested the above codes and it works fine.
Best regards,
Ji Zhou
Microsoft Managed MSDN Newsgroup Support Team