I want to capture certain, but not all, HttpWebRequest traffic in my application for debugging purposes. It\'s a web service hosted by IIS.
I have read How to: Conf
Here's how to wireup System.Net logging in code via reflection. Code is in VB but is trivial to convert to c#...
Dim logging = GetType(Net.HttpWebRequest).Assembly.GetType("System.Net.Logging")
Dim enabled = logging.GetField("s_LoggingEnabled", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Static)
enabled.SetValue(Nothing, True)
Dim webTr = logging.GetProperty("Web", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Static)
Dim tr as TraceSource = webTr.GetValue(Nothing, Nothing)
tr.Switch.Level = SourceLevels.Verbose
tr.Listeners.Add(New MyTraceListener())
Put this in Global.asax Application_Start() with whatever conditions you want to turn it on. You may need to Flush() tr before reading.