Custom WCF Tracing problem with “propagateActivity” Attribute

If you want to trace in the same trace source as WCF you can use this Example in Damir Dobric Blog. But if you use the WCF Configuration Editor to generate the System.Diagnostic section in the configuration file, this call will fail with the error “'propagateActivity' is not a valid configuration attribute for type 'System.Diagnostics.TraceSource'.” The Problem is that WCF uses his own TraceSource implemention, which has additional attributes, as the “propagateActivity”.

A simple solution to fix the problem is to have its own TraceSource implementation, which have all supported attributes of WCF Trace Source.

internal class WcfTraceSource : TraceSource
    /// <summary>
    /// Create the WCF Trace Source.
    /// </summary>
    internal WcfTraceSource()
        : base("System.ServiceModel")

    /// <summary>
    /// Gets the supported attributes from WCF
    /// "propagateActivity" and "logKnownPii"
    /// </summary>
    /// <returns>Returns the supported attributes.</returns>
    protected override string[] GetSupportedAttributes()
        string[] supportedAttributes = base.GetSupportedAttributes();
        if (supportedAttributes == null)
            return new string[] { "propagateActivity", "logKnownPii" };

        string[] newSupportedAttributes =
              new string[supportedAttributes.Length + 2];
        newSupportedAttributes[supportedAttributes.Length - 1] =                     



        newSupportedAttributes[supportedAttributes.Length] =  
        return newSupportedAttributes;



Posted May 26 2009, 10:50 AM by Rolf Nebhuth
Filed under: is a .Net Community Blog powered by daenet GmbH.