WCF tracing in code does not follow MessageLogging settings

☆樱花仙子☆ 提交于 2019-11-30 15:44:19

I can't comment on all of your code because I have not used System.Diagnostics in this way before (programmatically configuring the WCF communication tracing), but if your intent on this line:

traceSource.Switch.ShouldTrace(TraceEventType.Verbose | TraceEventType.Start);

Is to set the level of tracing that you want, I think that you should be using the Switch.Level property instead. ShouldTrace is for asking if a given TraceSource would trace, given the input flags.

traceSource.Switch.Level = SourceLevels.Verbose | SourceLevels.ActivityTracing; 

Note that according to this link, it is possible to configure apparently reasonable settings and yet the activity id might not be propogated correctly. Read it carefully. It may or not apply to your situation.

  1. You need to enable MessageLogging by defining a trace source as indicated in this MSDN Library page. So, you need this extra bit in your app.config in the sources section:

    <source name="System.ServiceModel.MessageLogging">
       <listeners>
         <add type="System.Diagnostics.DefaultTraceListener" name="dummy"/>
      <remove name="Default" />
    </listeners>      </source>
    

The message logging settings don't apply to the System.ServiceModel trace source.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!