仅对失败的请求进行WCF跟踪? [英] WCF tracing of ONLY failed requests?

查看:72
本文介绍了仅对失败的请求进行WCF跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将跟踪信息保存到.svclog文件中,但仅用于失败的请求.这可能吗?如果是这样,精确度如何?

I want to save trace information into .svclog files but only for failed requests. Is this possible? If so, how precisely?

我有一个WCF服务,每分钟被调用数百次.在极少数情况下,客户端会收到错误500,该错误500在WCF内运行的代码边界之外发生(通常是安全问题).我想确切地知道为什么会发生这些错误以及导致这些错误的原因.

I have a WCF service that's called hundreds of times per minute. On rare occasions clients will get an error 500 that occurs outside of the boundaries of my code running inside WCF (usually security issues). I'd like to know exactly why those errors are happening and what's causing them.

我也非常想使用跟踪查看器工具来检查.svclog文件.

I would also really like to use the Trace Viewer tool to examine the .svclog files.

据我所知,我有两个选择: 1)通过通过system.webServer \ tracing设置记录失败的请求来对FERB进行跟踪.不幸的是,我真的不喜欢IE跟踪查看器的界面,也没有从跟踪日志中获取足够的信息来弄清楚为什么我的代码之外发生了错误.

As far as I can tell, I have two options: 1) instrument FERB tracing by logging failed requests via system.webServer\tracing settings. Unfortunately, I really don't like the interface of the IE trace-viewer, nor do I get enough information from the trace-logs to figure out why an error outside of my code has occurred.

2)打开system.diagnostics \ trace部分下的全局跟踪.本节将生成出色的跟踪日志,其中包含我可能想要的所有捕获内容.但是,我无法找到一种方法来仅捕获失败请求的信息.本节捕获所有请求的跟踪信息.我的跟踪日志很快就填满了!

2) turn on the global tracing under system.diagnostics\trace section. This section produces great trace-logs with everything captured that I could ever want. However, I cannot find a way to only capture the information for failed requests. This section captures trace information for ALL requests. My trace logs quickly fill up!

我的错误500断断续续,很少见.最终,我希望始终使我的.svclog跟踪保持打开状态,但仅在发生失败的请求时才启动它.

My Errors 500 are intermittent and rare. Ultimately, I want to always have my .svclog tracing ON but only have it kick in when failed requests occur.

请告知是否可能?

谢谢!

格雷厄姆, 我已听从您的建议,但看不到我期望的日志.这是来自web.config的相关部分:

Graham, I've followed your advice and I'm not seeing the logs I expect. Here are relevant sections from the web.config:

<system.diagnostics>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                <filter type="" />
            </add>
        </listeners>
    </trace>

    <sources>
        <source name="System.ServiceModel" switchValue="Error">
            <listeners>
                <add name="wcfTracing" 
                         type="System.Diagnostics.XmlWriterTraceListener" 
                         initializeData="Traces1.svclog"/>
                <add name="log4netTracing"
                         type="AzureWatch.Model.Service.Log4netTraceListener,AzureWatch.Model.Service"/>
            </listeners>
        </source>
        <source name="System.ServiceModel.MessageLogging" switchValue="Error">
            <listeners>
                <add name="wcfTracing"
                         type="System.Diagnostics.XmlWriterTraceListener"
                         initializeData="Traces2.svclog"/>
                <!--<add name="log4netTracing"
                         type="AzureWatch.Model.Service.Log4netTraceListener,AzureWatch.Model.Service"/>-->
            </listeners>
        </source>
    </sources>
    </system.diagnostics>

<!-- ... -->

        <diagnostics wmiProviderEnabled="true">

        <messageLogging 
            logEntireMessage="true" 
            logMalformedMessages="true" 
            logMessagesAtServiceLevel="true" 
            logMessagesAtTransportLevel="true"
            maxSizeOfMessageToLog="1000000"
            maxMessagesToLog="-1" />
    </diagnostics>

这是WCF的客户端错误:

Here is the WCF's client error:

  <Exception>
    <Type>System.Net.Sockets.SocketException</Type>
    <Message>An existing connection was forcibly closed by the remote host</Message>
    <StackTrace>
      <Frame>at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)</Frame>
    </StackTrace>
  </Exception>

不幸的是,任何一个跟踪侦听器都未记录任何内容. 失败的请求日志包含以下内容:

Unfortunately there is NOTHING that's logged by either of the trace-listeners. Failed Request log contains this:

-GENERAL_READ_ENTITY_END 
    BytesReceived 0 
    ErrorCode 2147943395 
    ErrorCode The I/O operation has been aborted because of either a thread exit or an application request. (0x800703e3) 
     Warning
-MODULE_SET_RESPONSE_ERROR_STATUS 
    ModuleName ManagedPipelineHandler 
    Notification 128 
    HttpStatus 400 
    HttpReason Bad Request 
    HttpSubStatus 0 
    ErrorCode 0 
    ConfigExceptionInfo  
    Notification EXECUTE_REQUEST_HANDLER 
    ErrorCode The operation completed successfully. (0x0) 
    0 msInformational

推荐答案

我尝试为WCF服务输入以下配置,并使用有效和无效的凭证访问该服务.只有具有无效凭据的请求才会使任何内容显示在服务跟踪文件中.我的服务使用一个自定义的UserNamePasswordValidator类,该类存在于堆栈跟踪中.重要部分是<source>元素中的switchValue="Error"propagateActivity="false".不知道这是否正是您想要的东西,但是至少看起来很近...

I've tried putting in the following config for my WCF service, and hit the service with valid and invalid credentials. Only the requests with invalid credentials caused anything to appear in the service trace file. My service uses a custom UserNamePasswordValidator class, and this was present in the stack trace. The important parts are the switchValue="Error" and propagateActivity="false" in the <source> element. Not sure if this is exactly what you want, but it at least seems close...

<system.diagnostics>
  <sources>
    <source name="System.ServiceModel" switchValue="Error" 
            propagateActivity="false">
      <listeners>
        <add type="System.Diagnostics.DefaultTraceListener" name="Default">
          <filter type="" />
        </add>
        <add name="ServiceModelTraceListener">
          <filter type="" />
        </add>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add initializeData="C:\Path-to-log-file\Web_tracelog.svclog" 
         type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
         name="ServiceModelTraceListener" 
         traceOutputOptions="DateTime, Timestamp, Callstack">
      <filter type="" />
    </add>
  </sharedListeners>
  <trace autoflush="true" />
</system.diagnostics>

这篇关于仅对失败的请求进行WCF跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆