Click here to Skip to main content
Click here to Skip to main content

A TraceListener that sends messages via UDP

, 28 Jul 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
An implementation of a TraceListener that sends messages across the network.


Generating application log messages is important for diagnosing and testing a system, and a must for complex and large systems. .NET framework currently provides EventLogTraceListener and TextWriterTraceListener, which work fine for desktop applications; but for more complex server applications which need to be monitored/tested remotely, there is no solution.

Hence, I wrote this small utility NetTraceListener class that extends from TraceListener and outputs log messages to a defined UDP port.


You would require a basic UDP notes collector to see the UDP messages.


The entire source file is written in less than 20 lines of code.

The constructor takes a host name (e.g., "") and a port number, it creates a UDPClient object that is used to send UDP messages.

UdpClient notifier; 
IPEndPoint groupEP; 
public TraceNetListener( string host, int port ) 
 groupEP = new IPEndPoint( IPAddress.Parse( host ) ,port );
 notifier = new UdpClient(); 

The overridden method Close():

public override void Close() 
    base.Close ();

The overridden method Write(), it converts the supplied message into bytes, and sends them over a UDP channel.

public override void Write(string message) 
  byte[] bytes = Encoding.ASCII.GetBytes(message);
  notifier.Send(bytes, bytes.Length, groupEP);
 catch (Exception e) 

Now in your main application, you need to add this class as a trace listener.

Trace.Listeners.Add( new TraceNetListener("", 11000 )); 
Trace.Write("HELLO WORLD !");

And you are all set. When you execute this code, your UDP NoteCollector will get all your trace messages.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mayank Gupta
Web Developer
Australia Australia
No Biography provided

Comments and Discussions

General"UPD receiver" or "UDP notes collector" PinmemberStarCraft28-Apr-07 10:59 
GeneralSome thoughts PinmemberD. Emilio Grimaldo Tuñon5-Mar-05 0:06 
GeneralGreat Idea PinmemberJubjub12-Jan-05 16:11 
GeneralFile download link is broke PinmemberEric Engler2-Aug-04 10:51 
GeneralTraceTool PinmemberThierry Parent29-Jul-04 20:33 
GeneralRe: TraceTool Pinmembermitchellm4425-Jun-08 9:44 
GeneralProblems PinmemberAlois Kraus29-Jul-04 4:49 
GeneralRe: Problems PinmemberMayank Gupta29-Jul-04 20:39 
GeneralRe: Problems PinmemberThomas Lykke Petersen24-Jun-07 23:36 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150129.1 | Last Updated 29 Jul 2004
Article Copyright 2004 by Mayank Gupta
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid