【问题标题】:Is there any way to trace all exceptions in WCF?有没有办法跟踪 WCF 中的所有异常?
【发布时间】:2011-10-13 09:45:33
【问题描述】:

如何在 WCF 中启用对任何异常的跟踪(不管是处理还是未处理)?这是我配置的代码:

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Error,ActivityTracing"
        propagateActivity="true">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="tracelog.svclog"
        type="System.Diagnostics.XmlWriterTraceListener"
        name="ServiceModelTraceListener" traceOutputOptions="DateTime, Timestamp, Callstack">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>

然后我尝试在 SvcTraceViewer 中查看任何异常,但我没有看到异常。如何在跟踪日志中获取异常? 提前致谢!

【问题讨论】:

  • “处理没关系……” - 这是什么意思?显然,如果在 OperationContract 的实现中处理了异常,WCF 基础结构将永远不会看到它,因此 WCF 不可能记录。
  • 我的意思是在 try {} catch {} 块中处理的异常。

标签: c# .net wcf exception trace


【解决方案1】:

我在您的配置中没有看到明显的问题,但这是我使用的,我确实在 Svc Trace Viewer 中看到了异常:

    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
                <listeners>
                    <add name="XTL" />
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add initializeData="trace.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="XTL" />
        </sharedListeners>
        <trace autoflush="true" />
    </system.diagnostics>

【讨论】:

  • 能否请您指出 SvcTraceViewer 中可以看到异常的地方?
  • @kseen - 在活动视图中,您应该在列表中看到红色项目。单击其中之一后,右侧面板将显示特定的痕迹,包括再次代表异常的红色痕迹,以及详细信息和堆栈框架。
  • 不适用于异常自定义行为扩展?
猜你喜欢
  • 2010-12-24
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
  • 1970-01-01
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 2012-06-14
相关资源
最近更新 更多