Search code examples
wcfwcf-data-serviceswcf-bindingwcf-security

Can we apply filters to System.Net WCF tracing log?


I need to filter WCF System.Net trace log. Can we apply XPath filters to System.Net source, the way we apply to messageLogging?

My config file system.diagnostics section is as follows:

  <system.diagnostics>
    <sources>
      <source tracemode="protocolonly" name="System.Net" switchValue="Verbose">
        <listeners>
          <clear />
          <add name="textLogger">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="textLogger"
           type="System.Diagnostics.TextWriterTraceListener"
           initializeData="WCF_logswcf_svclog.txt">
        <filter type="System.Diagnostics.EventTypeFilter" initializeData="Verbose"/>
        </add>
    </sharedListeners>
    <trace autoflush="true" indentsize="4" />
  </system.diagnostics>

Solution

  • I was able to fix this issue. I used circular buffer trace listener project provided by Microsoft. I edited project to log data which is required by me. I have added following if condition in the TraceEvent() of CircularTraceListener class.

    if (eventType == TraceEventType.Verbose && message.Contains("requiredData"))
                {
                     base.TraceEvent(eventCache, source, eventType, id, message);
                }