System.Net (HttpWebRequest) tracing without using files or app.config?

后端 未结 3 1310
面向向阳花
面向向阳花 2020-12-05 08:16

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

3条回答
  •  情歌与酒
    2020-12-05 09:10

    You can create your own TraceListener implementation. The example(s) I have found online that configure things at run-time do not show working with the system trace sources. 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).

    Take the example in the following article and switch it from sending e-mails to publishing a static event that you can subscribe to when you're interested in receiving trace messages:

    Extending System.Diagnostics

    This does cause a performance hit since logging is enabled all the time (all or nothing as configured in the web.config). (See this article and comments explaining the importance of removing the default trace to improve performance.)

提交回复
热议问题