wcf trace and log config

本文介绍如何通过配置WCF服务的消息日志记录,包括设置消息日志的级别、输出位置等。通过具体示例展示了如何使用System.Diagnostics命名空间下的组件实现日志记录,并详细解释了基本HTTP绑定及安全配置。
<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>
    </sources>
    <sharedListeners>
      <add initializeData="..\..\app_messages.svclog"
          type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>

  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true"
                      logMessagesAtServiceLevel="true" />
    </diagnostics>
    <bindings>
      <basicHttpBinding>
                <binding name="Basic" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8090/service/basic" binding="basicHttpBinding"
                bindingConfiguration="Basic" contract="Contracts.IArithmetic" name="Basic" />
        </client>
    </system.serviceModel>
</configuration>

 

 

 

 

配置文件如上:在<system.diagnostics>配置节下的<sources>中配置源信息,源信息的name属性值为:System.ServiceModel.MessageLogging,这表明源为在<system.serviceModel>配置节下的<messageLogging>。source 中的 listener可以添加很多种,这里添加了“System.Diagnostics.DefaultTraceListener”和“

System.Diagnostics.XmlWriterTraceListener”。经过这样配置之后,wcf的trace log 将output到"..\..\app_messages.svclog",和默认的窗口。

so easy!!!!

 

 

转载于:https://www.cnblogs.com/weishuai/archive/2011/04/28/2031468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值