【问题标题】:WCF Tracing won't write to file?WCF 跟踪不会写入文件?
【发布时间】:2014-04-23 15:32:54
【问题描述】:

我已在 WCF 服务中启用跟踪。这是 system.diagnostics 部分:

<configuration>
  <system.diagnostics>
    <trace autoflush="true"/>
    <sources>
      <source name="System.ServiceModel" switchValue="All" propagateActivity="true">
        <listeners>
          <add name="xmlTraceListener" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="All">
        <listeners>
          <add name="xmlTraceListener" />              
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xmlTraceListener"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="C:\KryptonTracing\Traces.svclog" />
    </sharedListeners>
  </system.diagnostics>

这里的 system.serviceModel 部分仅显示诊断:

<diagnostics wmiProviderEnabled="true">
  <messageLogging
       logEntireMessage="true"
       logMalformedMessages="true"
       logMessagesAtServiceLevel="true"
       logMessagesAtTransportLevel="true"
       maxMessagesToLog="3000"
   />
</diagnostics>

当我发布服务时,我在服务器上的 Windows 事件查看器中看到一个信息事件,内容如下:

消息记录已开启。敏感信息可能是 以明文方式登录,即使它是在网络上加密的:对于 例如,消息正文。

当我转到服务器上的 C:\KryptonTracing 文件夹时,没有生成 Traces.svclog。我已经进入 IIS 并查看了此 WCF 服务正在运行的应用程序池标识,并赋予该标识对文件夹的完全控制权.. 仍然没有。无论我做什么,我都无法创建 Traces.svclog。仅供参考,此服务是具有自定义身份验证的 wsHttpBinding (SSL),但这无关紧要。

我试过everything in this post 无济于事。请帮忙。

【问题讨论】:

  • 为什么你的&lt;system.diagnostics&gt;&lt;configSections&gt;下面?是错字吗?它应该在根标签&lt;configuration&gt;下。
  • 抱歉打错了,我已经编辑了帖子。
  • WCF 服务工作正常吗?也许一个请求永远不会到达 WCF 以被记录。我看不出你的配置有什么问题。
  • 是的,该服务正在运行。我可以使用客户端来证明请求正在通过并且数据库正在更新。我还可以查看 IIS 日志并查看正在命中的服务。该服务具有 wsHttpBinding 和自定义身份验证,但这应该不是问题。
  • 当您为 System.ServiceModel.MessageLogging 和 System.ServiceModel 设置单独的日志文件时,它是否有效?尝试为 C:\KryptonTracing 文件夹上的每个人设置权限。只是为了确定:)

标签: wcf trace system.diagnostics


【解决方案1】:

我最终使用 WCF 配置编辑器将跟踪添加到 web.config。它在我的 web.config 中生成了这两个部分。

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\Tracing\Krypton_Web_messages.svclog"
           type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           name="ServiceModelMessageLoggingListener" 
           traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
      <add initializeData="C:\Tracing\Krypton_Web_tracelog.svclog"
           type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           name="ServiceModelTraceListener" 
           traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

...还有这个:

<diagnostics>
  <messageLogging logEntireMessage="true" logMalformedMessages="true"
    logMessagesAtTransportLevel="true" />
</diagnostics>

然后,在发布之前,我创建了 C:\Tracing 文件夹并添加了具有完全权限的“所有人”。最后我发布了,现在两个 .svclog 文件在文件夹中!!!!不知道为什么我的原始配置一开始就不起作用。

【讨论】:

  • 谢谢你帮助我,我错过了配置的第二部分。对其他人来说,这应该放在 标签内
【解决方案2】:

遇到同样的问题,我注意到app.config gui 编辑器正在用西班牙语(我使用的 VS 语言环境)编写switchValue="Advertencia,ActivityTracing"

我将其更改为 switchValue="Warning,ActivityTracing" 并且有效。日志文件现已创建。
在线搜索“TraceLevel Enumeration”以查看可用选项。

【讨论】:

    猜你喜欢
    • 2010-11-08
    • 2012-04-27
    • 2011-04-04
    • 2011-02-20
    • 2012-10-03
    • 2023-03-29
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多