有没有办法跟踪WCF中的所有异常?

时间:2011-10-13 09:45:34

标签: c# .net wcf exception trace

如何在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中看到任何异常我没有看到异常。如何在跟踪日志中获取异常? 提前谢谢!

1 个答案:

答案 0 :(得分:2)

我没有在配置中看到明显的问题,但这是我使用的,我确实在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>