wcf 跟踪和消息日志记录 :http://msdn.microsoft.com/zhcn/library/ms751526.aspx

启用跟踪和消息日志记录。生成的跟踪和消息日志可以使用service tracer viewer查看:

在 WCF 中,可通过设置服务模型跟踪源 switchValue 并将下面的代码添加到服务或客户端的配置文件中来实现此目的:

<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>
            </sources>
            <sharedListeners>
            <add initializeData="C:\logs\TracingAndLogging-service.svclog" type="System.Diagnostics.XmlWriterTraceListener"
            name="xml" />
            </sharedListeners>
            <trace autoflush="true" />
            </system.diagnostics>
原文地址:https://www.cnblogs.com/liangouyang/p/1316211.html