使用 WCF LOB 适配器 SDK 跟踪适配器

WCF LOB 适配器 SDK 跟踪基于 Systems.Diagnostics 构建。 将 Microsoft.ServiceModel.Channels 跟踪源用于 WCF LOB 适配器 SDK 运行时。 使用 Microsoft.ServiceModel.Channels.Tools.MetadataSearchBrowse 跟踪源添加适配器服务引用插件和使用适配器服务外接程序。 WCF 跟踪将写入名为 System.ServiceModel 的源。

适配器开发人员可以使用 Microsoft.ServiceModel.Channels.Common.AdapterTrace 类为适配器提供跟踪源名称。 适配器开发向导生成一个跟踪包装类,适配器开发人员可以使用该类在适配器代码中提供检测。

有关 WCF 跟踪的信息,请参阅 跟踪

有关在 WCF 中分析跟踪的信息,请参阅 服务跟踪查看器工具 (SvcTraceViewer.exe)

示例跟踪包装器实用工具类

public class EchoAdapterUtilities  
{  
    static AdapterTrace trace = new AdapterTrace("Microsoft.Adapters.Samples.Echo.EchoAdapter");  
  
    /// <summary>  
    /// Gets the AdapterTrace  
    /// </summary>  
    public static AdapterTrace Trace  
    {  
        get  
        {  
            return trace;  
        }  
    }  
}  

然后,适配器开发人员可以在整个适配器代码中使用上一个实用工具类,为适配器使用者提供检测数据。

EchoAdapterUtilities.Trace.Trace (System.Diagnostics.TraceEventType.Information, “EchoAdapterConnection::Open”, “Connection 已成功打开!”) ;

为适配器和 WCF LOB 适配器 SDK 运行时启用跟踪

通过使用适配器在应用程序的 app.config 文件中添加以下部分,可以启用 WCF LOB 适配器 SDK 中提供的跟踪。

<system.diagnostics>  
  <sources>  
    <source name="Microsoft.Adapters.Samples.Echo.EchoAdapter" switchValue="Verbose">  
      <listeners>  
        <add name="xmlTrace" />  
      </listeners>  
    </source>  
    <source name="Microsoft.ServiceModel.Channels" switchValue="Verbose">  
      <listeners>  
        <add name="xmlTrace" />  
      </listeners>  
    </source>  
  </sources>  
  <sharedListeners>  
    <add initializeData="C:\logs\TestEchoAdapter_Browse.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xmlTrace">  
      <filter type="" />  
    </add>  
  </sharedListeners>  
  <trace autoflush="true" />  
</system.diagnostics>  

可以使用 add 元素来指定要使用的跟踪侦听器的名称和类型。 在示例配置中,我们将侦听器命名为“xmlTrace”,并将标准.NET Framework跟踪侦听器 (System.Diagnostics.XmlWriterTraceListener) 添加为要使用的类型。 可以为每个源添加任意数目的跟踪侦听器。 例如,在以下示例中,我们还添加了另一个名为“textTrace”的侦听器,该侦听器使用.NET Framework跟踪侦听器 System.Diagnostics.TextWriterTraceListener。 如果跟踪侦听器发出对文件的跟踪,则您必须在配置文件中指定输出文件的位置和名称。 这是通过将 initializeData 设置为该侦听器的文件的名称来完成的。

为添加适配器服务引用插件启用跟踪

可以通过在 位于 \Program Files (x86)\Microsoft Visual Studio\Common7\IDE中的 devenv.exe.config 文件中添加以下部分来为此插件启用跟踪。

<system.diagnostics>  
   <sources>  
    <source name="Microsoft.ServiceModel.Channels.Tools.MetadataSearchBrowse" switchValue="Verbose, ActivityTracing">  
      <listeners>  
        <add name="textTrace"/>  
      </listeners>  
    </source>  
  </sources>  
  <sharedListeners>  
    <add initializeData="C:\logs\aasr.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xmlTrace">  
      <filter type="" />  
    </add>  
    <add initializeData="C:\logs\aasr.log" type="System.Diagnostics.TextWriterTraceListener" name="textTrace">  
      <filter type="" />  
    </add>  
  </sharedListeners>  
  <trace autoflush="true" indentsize="4" />  
</system.diagnostics>  

为使用适配器服务外接程序启用跟踪

可以通过在 位于 \Program Files (x86)\Microsoft BizTalk Server中的 BTSNTSVC.exe.config 文件中添加以下部分来为此外接程序启用跟踪。

<system.diagnostics>  
   <sources>  
    <source name="Microsoft.ServiceModel.Channels.Tools.MetadataSearchBrowse" switchValue="Verbose, ActivityTracing">  
      <listeners>  
        <add name="textTrace"/>  
      </listeners>  
    </source>  
  </sources>  
  <sharedListeners>  
    <add initializeData="C:\logs\aasr.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xmlTrace">  
      <filter type="" />  
    </add>  
    <add initializeData="C:\logs\aasr.log" type="System.Diagnostics.TextWriterTraceListener" name="textTrace">  
      <filter type="" />  
    </add>  
  </sharedListeners>  
  <trace autoflush="true" indentsize="4" />  
</system.diagnostics>  

另请参阅

对使用 WCF LOB 适配器 SDK 创建的适配器进行故障排除