NotificationFormTraceListener Assembly

By Fons Sonnemans, 26-11-2007

Download (VS2005 Solution, C# 2.0)


During development, you can use the output methods of the Debug class to display messages in the Output window of the Visual Studio 2005 integrated development environment (IDE). For example:

' Visual Basic
Trace.WriteLine("Hello World!")
Debug.WriteLine("Hello World!")

// C#
Trace.WriteLine("Hello World!");
Debug.WriteLine("Hello World!");

Each of these examples will display "Hello World!" in the Output window when the application is run in the debugger.

The .NET TraceListners monitor trace and debug output. You use TraceListners to redirect this output to a specific medium. There are 3 TraceListners available: DefaultTraceListener, EventLogTraceListener and TextWriterTraceListener.

The NotificationFormTraceListener is a special TraceListner which allows you to monitor the output in a special TraceForm which can be activated using a Notification icon.

Sample: TraceForm used to monitor SQL statements


The NotificationFormTraceListener can be used in a Windows application. You have to create one and add it to the (static) Listeners collection of the System.Diagnostics.Trace class.

Don't forget to Dispose the listener when you exit the application. This is necessary because an extra Thread is used for the NotificationFormTraceListener. This Thread doesn't stop automatically.

/// <summary>
/// The main entry point for the application.
/// </summary>
staticvoid Main()
    // Initialize the TraceListener
        m_listner=new ReflectionIT.Diagnostics.NotificationFormTraceListener();

    // Add it to the Listeners collection

    // Run the MainForm
    Application.Run(new TraceFormTest());

    // Dispose all TraceListeners
    foreach (TraceListener l in Trace.Listeners){
Sample: static Main

The ContextMenu of the NotificationIcon makes it possible to Open the TraceForm, set the 'Always on Top' option and Exit.

Add Tracing using the Configuration file

You can add TraceListeners from your code but you can also add them by editing the configuration file that corresponds to the name of your application. Within this file, you can add a listener, set its type and set its parameter, remove a listener, or clear all the listeners previously set by the application.

type="ReflectionIT.Diagnostics.NotificationFormTraceListener, ReflectionIT.Diagnostics"
                     initializeData="Buffy.NET Demo Trace"/>
Sample: BuffyDemo.exe.config


TraceListers can help you to debug your code. The NotificationFormTraceListener helps you to monitor the Trace and Debug output in more convenient way.

Any suggestions and feedback for improving this article is most welcome. Send your suggestions and feedback to

Thanks to:

  • Damien Pitman who reported and solved a threading problem (bug).
Tags: CSharp

Leave a Comment

Leave a Comment
3 + 8 =


All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.