如何启用WCF跟踪?

时间:2010-11-24 21:01:19

标签: wcf

更新

我一直试图启用WCF跟踪,但仍然没有成功......以下是我最新的更新。

我是否需要获得写入以下位置的权限?

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "@\\myservername\folder1\traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

我正在使用.NET Framework 3.5。

为了调试目的,打开WCF跟踪的逐步说明是什么?

4 个答案:

答案 0 :(得分:217)

可以应用从MSDN获取的以下配置来启用WCF服务上的跟踪。

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
             <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
            <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="Information, ActivityTracing">
        <listeners>
            <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
        <add name="xml"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData="Error.svclog" />
    </sharedListeners>
  </system.diagnostics>
</configuration>

要查看日志文件,您可以使用“C:\ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ SvcTraceViewer.exe”。

如果您的系统上没有“SvcTraceViewer.exe”,您可以从“Microsoft Windows SDK for Windows 7和.NET Framework 4”软件包下载它:

Windows SDK Download

您不必安装整个内容,只需安装“.NET开发/工具”部分。

如果/如果它在安装过程中因非感性错误而被炸出,Petopas' answer to Windows 7 SDK Installation Failure解决了我的问题。

答案 1 :(得分:30)

在您的web.config中(在服务器上)添加

<system.diagnostics>
 <sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
   <listeners>
    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\logs\Traces.svclog"/>
   </listeners>
  </source>
 </sources>
</system.diagnostics>

答案 2 :(得分:14)

转到Microsoft SDKs目录。像这样的道路:

//propertyfile.js
export const myName = "Username";
export const myURL = "www.google.com",
export const reactNativeUser = true;
export const age = 22;

//component.js
import {myName, myURL, reactNativeUser, age} from 'propertyfile'

从该目录中打开WCF配置编辑器(Microsoft服务配置编辑器):

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools

(打开此工具的另一个选项是在Visual Studio 2017中导航到&#34;工具&#34;&gt;&#34; WCF服务配置编辑器&#34;)

wcf configuration editor

使用编辑器打开.config文件或创建一个新文件,然后导航到诊断程序。

您可以点击&#34;启用MessageLogging&#34;。

enable messagelogging

更多信息:https://msdn.microsoft.com/en-us/library/ms732009(v=vs.110).aspx

使用来自同一目录的跟踪查看器,您可以打开跟踪日志文件:

SvcConfigEditor.exe

您还可以使用WMI启用跟踪。更多信息: https://msdn.microsoft.com/en-us/library/ms730064(v=vs.110).aspx

答案 3 :(得分:1)

您可以尝试使用VS SDK附带的WCF配置编辑器来启用跟踪,而不是手动将跟踪启用位添加到web.config中

https://stackoverflow.com/a/16715631/2218571

相关问题