This project has moved and is read-only. For the latest updates, please go here.

TraceConfigurationMonitor Class

Monitors the application configuration file and refreshes the tracing configuration when the file is changed.


Install via NuGet (this package is automatically installed when you install one of the trace listeners):


The TraceConfigurationMonitor sets up a FileSystemWatcher that is watching the application config file. When it detects a change it calls Trace.Refresh() to reload the diagnostics configuration. Note that you don't need this class for web applications, as they restart when web.config is editted.

Note: If you try to add a filter to an existing listener (that doesn't already have a filter) you will cause a NullReferenceException. A work around is to also change the name of the listener (effectively creating a new one), and update the references in any trace sources.


In your application, create and start the configuration monitor. For example in a Windows Service you could use the following:

public partial class ExampleService : ServiceBase
    TraceConfigurationMonitor configMonitor;

    protected override void OnStart(string[] args)
        configMonitor = new TraceConfigurationMonitor();

        // ... run the service ...
    // ...

Now if you change the application config file (while it is running), the diagnostics configuration is reloaded.

When your application ends you can clean up by stopping and disposing the configuration monitor:

    protected override void OnStop()

Last edited Feb 6 at 5:56 AM by sgryphon, version 6


No comments yet.