WCF tracing in code does not follow MessageLogging settings

后端 未结 2 1495
花落未央
花落未央 2021-01-03 10:23

I need to use WCF tracing in my application but it needs to be controlled from code as much as possible.

IT was suggested that I install the following sections in my

相关标签:
2条回答
  • 2021-01-03 10:42

    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.

    0 讨论(0)
  • 2021-01-03 11:02
    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.

    0 讨论(0)
提交回复
热议问题