views:

118

answers:

1

I'm trying to get access to some diagnostic information available in the .NET System.Net tracing functionality in my application.

I am aware that I can set the tracing level using the appropriate .config, but I was hoping to be able to toggle the switch programatically. (i.e. turn tracing on during particular parts of my program execution).

Is there a way for me to toggle the TraceSwitch/TraceSources used by the System.Net tracing functionality in code?

I'm aware of This SO question, but that situation seems different because the underlying issue there is that the library in question is creating a new TraceSwitch for each write call.

A: 

If you don't mind getting your hands dirty you could try using reflection to toggle the private static bool System.Net.Logging.s_LoggingEnabled (.NET 2).

See further details and alternatives in this question.