在WCF中写入错误日志 [英] Writting error log in WCF

查看:180
本文介绍了在WCF中写入错误日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
请告诉我如何在wcf中写入日志文件以了解错误和异常.

Hello friends ,
please tell me how can I write log file in wcf for erros and exceptions.

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_svc_CRUD"

                 maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"

                 receiveTimeout="00:40:00" openTimeout="00:40:00"

                 closeTimeout="00:40:00" sendTimeout="00:40:00">
          <readerQuotas maxDepth="2147483647"

              maxStringContentLength="2147483647" maxArrayLength="2147483647"

              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" ignoreExtensionDataObject="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <services>
      <service name="wcfsvc_master.Session">
        <endpoint address="" binding="basicHttpBinding" contract="wcfsvc_master.ISession" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="wcfsvc_master.svc_CRUD">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_svc_CRUD"

        contract="wcfsvc_master.Isvc_CRUD" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <timeouts closeTimeout="00:15:00" openTimeout="00:10:00" />
        </host>

      </service>
    </services>
    <client>
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_svc_CRUD"

     contract="wcfsvc_master.Isvc_CRUD" />
    </client>
    <diagnostics>
      <messageLogging

            logEntireMessage="true"

            logMalformedMessages="false"

            logMessagesAtServiceLevel="true"

            logMessagesAtTransportLevel="false"

            maxMessagesToLog="3000"

            maxSizeOfMessageToLog="2000"/>
    </diagnostics>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messages"

          type="System.Diagnostics.XmlWriterTraceListener"

          initializeData="C:\logs\messages.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
<

推荐答案

在配置服务的web.config中尝试此操作. br/>
try this in web.config where the services are configured.
<system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing" propagateActivity="true">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type=""/>
          </add>
          <add name="ServiceModelTraceListener">
            <filter type=""/>
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\\Users\\santhosh.kumar\\Desktop\\LS Evaluations\\Logs" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type=""/>
      </add>
    </sharedListeners>
  </system.diagnostics>



并在您的服务行为中添加以下行.
< servicedebug includeexceptiondetailinfaults ="true">

样本:



and in your service behaviors add the below line.
<servicedebug includeexceptiondetailinfaults="true">

Sample:

<behavior name="UtilityServiceBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>


可以在这里找到完整说明的文章
A fully explained article can be found here http://www.gonetdotnet.info/common-doubts/wcf/how-to-track-wcf-errors-and-exceptions[^]


这篇关于在WCF中写入错误日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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