Click here to Skip to main content
13,505,141 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


17 bookmarked
Posted 25 Feb 2008

Real-Time Tracing Library

, 25 Feb 2008
Rate this:
Please Sign up or sign in to vote.
Trace listener to publish debug messages on network (Publisher-Subscriber Pattern)


This article illustrates how to enable your .NET application to publish its trace/debug messages on the network so that the desired clients can subscribe to it and view them in real-time as they occur. The core idea is to design a custom trace listener which would listen on a port for incoming client connections and broadcast the trace messages to the connected clients. You can also find this ongoing project here.


In .NET, we have objects called Trace Listeners. A listener is an object that receives the trace output and outputs it somewhere; that somewhere could be a window in your development environment, a file on your hard drive, a Windows Event log, an SQL Server or Oracle database, or any other customized data store.

You can think of a Trace Listener as a conduit for passing tracing information from your application to the output store. We write tracing information on Trace Listeners and Trace Listeners in turn output the tracing information to the target media.

Storing tracing information in a data store of some sort provides the flexibility of analyzing the data later on and helps us find the error and performance related patterns in our applications. The System.Diagnostics namespace provides the interfaces, classes, enumerations and structures that are used for tracing, debugging, and other application and system diagnostic services. In this article, we will focus only on Tracing.

The System.Diagnostics namespace provides two classes named Trace and Debug that are used for writing errors and application execution information in logs. These classes are helpful during development (to output debug messages, etc.) and after deployment (to output performance related patterns, etc.). These two classes are the same, except that the methods of the Trace class become part of the release build code whereas methods of the Debug class don't become part of the release build executable.

When you create a new project, define the DEBUG symbol to enable output with the Debug class and the TRACE symbol to enable output with the Trace class. If you create a project in Visual Studio .NET, its Debug version will have these symbols defined.

Using the Code

Trace monitor is a diagnostics tool which facilitates you to see the trace output of your .NET application in real-time. This contains two components:

  1. TcpTraceListener.dll
  2. TraceMonitor.exe

TcpTraceListener.dll is the plug-in library which will route your trace out to the specified port. TraceMonitor.exe is a simple TCP client which facilitates to see the trace output. Alternatively, you can always look at the trace output by making a telnet to the specified port.

Steps to Install

  1. Copy TcpTraceListener.dll and TraceMonitor.exe to a directory, say C:\Temp
  2. Register TcpTraceListener.dll to GAC if you need to use it in system wide, issuing gacutil command at Visual Studio command prompt. [gacutil –I C:\Temp\TcpTraceListener.dll]
  3. Add reference to TcpTraceListener.dll for the project you desire. [I've done it for viewing the request and response XML in real-time]
  4. Add this to the list of trace listeners. [Param.TraceListener.TcpTraceListener objTcpTraceListener = new Param.TraceListener.TcpTraceListener(9090); System.Diagnostics.Trace.Listeners.Add(objTcpTraceListener);]
  5. Write trace/debug statements as usual. [Trace.Write(strRequest)]
  6. Run TraceMonitor.exe
  7. Use “Settings” menu to set the IP address and Port to which it should listen for trace output. [By default, its and 9090]
  8. Say “Connect”. And, here you go…
  9. Alternatively, you can always use telnet.


  1. You can see the trace output in real-time as it occurs.
  2. Makes your life easy in debugging.
  3. Multiple users can see the trace output of a single application and of course vice-versa.


  • 25th Feb, 2008 - Baseline (v1.0)


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Paramesh Gunasekaran
Technical Lead HCL Technologies
India India
Paramesh Gunasekaran is currently working as a Software Engineer in HCL Technologies, India. He obtained his Bachelor's degree in Information Technology from Anna University, India. His research areas include Computational Biology, Artificial Neural Networks and Network Engineering. He has also received international acclaim for authoring industry papers in these areas. He is a Microsoft Certified Professional in ASP.NET/C# and has also been working in .NET technologies for more than 8 years.


You may also be interested in...


Comments and Discussions

QuestionHow is this different than Instrumentation Pin
Member 20651894-Mar-08 3:38
memberMember 20651894-Mar-08 3:38 
GeneralRe: How is this different than Instrumentation Pin
Paramesh Gunasekaran5-Apr-08 8:00
memberParamesh Gunasekaran5-Apr-08 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180417.1 | Last Updated 25 Feb 2008
Article Copyright 2008 by Paramesh Gunasekaran
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid