【问题标题】:C# System.Net trace log - only trace one method and ignore others?C# System.Net 跟踪日志 - 只跟踪一种方法而忽略其他方法?
【发布时间】:2011-10-23 17:42:09
【问题描述】:

我正在使用 System.Net 跟踪,如下所述:

http://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html

但这会跟踪使用 HttpWebRequest 发出的每个请求。跟踪文件很大。我只想跟踪调用某个 URI 时发生的情况,例如:

https://api.example.com/oauth/RequestToken

因为在我的网络应用运行了几个小时后,连接到这个 URI 出现了问题。

我想忽略对其他 URI 的所有请求,例如:

https://api.example.com/Foo

因为这些请求运行良好,并且正在用我不需要的数据填充日志。

【问题讨论】:

  • 您是否使用 svcTraceViewer 工具查看跟踪信息?它使浏览数据变得更加容易,而不是直接查看 .xml 跟踪输出。
  • 不,我正在使用 TextWriterTraceListener 写入文本文件。问题不仅在于庞大的数据量,还在于巨大的文件大小。所以我宁愿以某种方式阻止它写所有东西。

标签: c# httpwebrequest trace system.diagnostics system.net


【解决方案1】:

您可能想看看Message Filters(向下滚动页面大约一半到名为“消息过滤器”的部分。)另一个页面here 专门用于消息记录过滤器。以下是对您的示例的配置应该是什么样子的有根据的猜测:

<messageLogging logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="true" >
   <filters>
        <add xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
                xmlns:a="http://www.w3.org/2005/08/addressing">
            /soap:Envelope/soap:Header/a:Action[starts-with(text(),'https://api.example.com/oauth/RequestToken')]
        </add>
   </filters>
</messageLogging>

还有一个跟踪日志过滤器here 的自定义实现可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 2017-06-27
    • 2015-09-27
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多