我使用以下代码实现了 WCF 跟踪:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="All"
propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="CardSpace" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.IO.Log" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.IdentityModel" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="c:\wcflogs\trace.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="Default" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics wmiProviderEnabled="true">
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
maxMessagesToLog="500" maxSizeOfMessageToLog="5000" />
</diagnostics>
</system.serviceModel>
但它只跟踪在 try/catch 块之外抛出的异常,所以当我想在我的跟踪中有这个异常时,我需要删除 try/catch 块。有没有办法在我的 WCF 跟踪中也有 try {} 的这个异常?