Click here to Skip to main content
6,634,665 members and growing! (15,351 online)
Email Password   helpLost your password?
Web Development » Trace and Logs » Debug and Tracing     Intermediate License: The Code Project Open License (CPOL)

A simple solution to see the inside of your code

By Maze

A simple solution to see the inside of your code.
C#, .NET CF, .NET 1.1, Win2K, WinXPVS.NET2003, Architect, Dev, QA
Posted:21 Sep 2005
Updated:25 May 2006
Views:31,231
Bookmarked:39 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 4.86 Rating: 4.50 out of 5
1 vote, 8.3%
1

2
1 vote, 8.3%
3
1 vote, 8.3%
4
9 votes, 75.0%
5

Introduction

Have you ever wanted to see what happens inside of your code? This project catches in real time every trace message from your application, centralizes them, and shows them on your screen in a friendly way.

The package contains five projects:

  • Tracer is a pipe server, and it receives all the trace messages and shows them on the interface.
  • EsiListener is a custom listener and also the pipe client. It sends all the trace messages to the server.
  • CPPEsiListener a C++ DLL used to send messages to MyTracer.
  • Client is a C# demo application. It can be your application.
  • CPPClient is a C++ demo application.

How it looks

Features

  • It is very easy to add or remove without changing your code.
  • Works with every application which respects standard tracing mode.
  • Works with different applications at the same time.
  • Locates the trace messages inside your application.
  • Traces objects and display all their properties and values.

How to use it

  • The Listener can be added from the source code:
    Trace.Listeners.Add( new Esi.Diagnostics.Listener() );
  • The Listener can be added from your application Config file like shown below:
    <system.diagnostics>  
        <trace>    
          <listeners>    
              <add name="myListener" 
                 type="Esi.Diagnostics.Listener, esiListener"/>    
              <remove 
                 type="System.Diagnostics.DefaultTraceListener"/>
          </listeners>   
        </trace> 
    </system.diagnostics>
  • For tracing, just use the standard tracing:
    Trace.WriteLine( " Hello world :) " ); 
    Trace.Write( "Hello again :P" );
  • If you want MyTracer to recognize your message as an error, information, or warning, use the convention described below:
    • error -> message has to start with [E],
    • warning -> message has to start with [W],
    • information -> message has to start with [I],
    • service -> message has to start with [S] (reserved for MyTracer application),
    • unknown messages -> any other messages.
    Trace.Write( "[E]Uuuups error :( " );
  • An interesting option is that you can trace object values with one call:
    Point p1 = new Point( 5, 5);
    Trace.WriteLine( p1 );
  • If you don't want to copy esiListener.dll in every application directory, you can insert esiListener.dll in the global assembly cache.
    gacutil -i esiListener.dll
  • For C++, copy the EsiListenerCPP.dll near the application. Add in the application project, Diagnostics.h and cpp (Set option: Do not use the precompiled header for the Diagnostic.cpp file). Before starting tracing, call:
    Trace::Init();

    For trace, call:

    Trace::WriteLine("Trace from C++");

    Convention for erorr[E], warning[W], and information[I] works here.

References

  • Inter-Process Communication in .NET Using Named Pipes, Part 1, by Ivan L.
  • TraceListeners and Reflection, by Jerry Dennany.

Others

I have updated this article especially for ninjacross :). That's all, and thank you for your attention.

License

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

About the Author

Maze


Member
I spend most of my working time in C# and C++. I am working for a Norwegian company called Hatteland Computer developing solutions for printing documents, data access layers, monitoring tools, that are integrated in the Rambase system.
Occupation: Software Developer
Company: Hatteland Computer
Location: Norway Norway

Other popular Trace and Logs articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
QuestionNice work! However... Pinmemberke4vtw8:21 13 May '08  
AnswerRe: Nice work! However... PinmemberMaze11:30 14 May '08  
GeneralNot thread safe PinmemberNinjaCross13:25 29 Sep '05  
GeneralRe: Not thread safe PinmemberMaze5:45 20 Oct '05  
GeneralRe: Not thread safe PinmemberNinjaCross4:18 16 May '06  
JokeRe: Not thread safe PinmemberMaze12:00 25 May '06  
GeneralRe: Not thread safe PinmemberNinjaCross13:13 25 May '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 May 2006
Editor: Smitha Vijayan
Copyright 2005 by Maze
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project