Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6746807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:21:58+00:00 2026-05-26T12:21:58+00:00

I recently read Chris Love’s advice on using WCF Tracing to help with troubleshooting

  • 0

I recently read Chris Love’s advice on using WCF Tracing to help with troubleshooting.
He turns on the tracing by adding new sections of XML to the app.config file and I have since seen similar recommendations here for the same technique.

However we don’t really want to ship multiple app.config files.
And we definitely don’t want our customers modifying them on production systems!

Is there a way that the various settings for WCF Tracing can be set up in the app.config, but the tracing is turned on/off from code?

Ideally I’d like my application to check the registry and only activate the tracing when a certain value was present.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:21:59+00:00Added an answer on May 26, 2026 at 12:21 pm

    My suggestion is to use a custom TraceFilter which you apply to all listeners attached to the WCF TraceSources (i.e., “System.ServiceModel”, “System.ServiceModel.MessageLogging”). Inside the TraceFilter’s ShouldTrace() method you can then conditionally suppress tracing based on any information that’s available to the app.

    Here is some sample code which you could use as a starting point. There is a static helper class which determines globally and once during the lifetime of an app whether tracing should be enabled or disabled:

    namespace WCF.Diagnostics
    {
        using System.Diagnostics;
    
        public static class WcfDiagnosticsHelper
        {
            private readonly static bool _shouldTraceWcf;
    
            static WcfDiagnosticsHelper()
            {
                // here, determine if WCF Tracing should be enabled or not
                // i.e., read some custom settings from App.config or the registry etc...
    
                _shouldTraceWcf = true;
            }
    
            internal static bool ShouldTraceWcf
            {
                get { return _shouldTraceWcf; }
            }
        }
    
        public class WcfTraceFilter : TraceFilter
        {
            public override bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
            {
                // In here, check the static 'ShouldTraceWcf' property as well as the name of the originating TraceSource
                if (source != null && source.StartsWith("System.ServiceModel") && !WcfDiagnosticsHelper.ShouldTraceWcf)
                    return false;
                return true;
            }
        }
    }
    

    In the App.config you’d configure the TraceFilter like this:

    <system.diagnostics>
      <sources>
        <source name="System.ServiceModel" propagateActivity="true" switchValue="Warning">
          <listeners>
            <add name="LocalXmlFile" initializeData="WcfTracing.svclog" type="System.Diagnostics.XmlWriterTraceListener">
              <filter type="WCF.Diagnostics.WcfTraceFilter, WCF_Custom_TraceFilter"/>
            </add>
          </listeners>
        </source>
      </sources>
    </system.diagnostics>
    

    **

    Please note that a similar behavior could be achieved by writing a custom Trace Switch. The main difference would be that a TraceSwitch is applied to a TraceSource, and a TraceFilter to a TraceListener. It would be slightly more involved, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently read a nice post on using StringIO in Ruby. What the author
I recently read this thread on MSDN . So I was thinking of using
I recently read in a magazine that there is a new commercial developer tool
I am new in flex and recently read about Validation and Invalidation in components
I recently read about a new Google-code hosted (open source) project from Google that
VB.NET 2010, .NET 4 Hello, I recently read about using SynchronizationContext objects to control
I recently read how to disable scripting for an entire application by adding the
I've recently read this article on using printf and scanf in assembly: Meaning of
I am using ColdFusion 9.0.1 I recently read that in ColdFusion 9, it is
I recently read an article about c#-5 and new & nice asynchronous programming features

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.