Click here to Skip to main content
12,950,832 members (59,176 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 31 Aug 2002

Debug Console Window

, 1 Sep 2002
Rate this:
Please Sign up or sign in to vote.
A console window class useful for debugging, reporting events during runtime and saving logs on disk.


I usually send various debug messages to .txt files or the standard console, but I somehow got tired of this DOS feeling... Interactive functions like saving the whole output to a file with one click or easily clearing the list are not available as well. So I started writing this dialog console. The DebugConsole class is a singleton that has the Form class as member, this seemed the best way in C# to have this class acting like a global variable.

The first version didn't have any support for the listening code of .NET and Richard D. proposed to derive this class from System.Diagnostics.TraceListener, very good idea indeed as it simplified the calls too, thanks Richard. You just need to include the System.Diagnostics namespace and call the DebugConsole.Instance.Init() method. The first parameter tells if you want to set the debug listener (true) or the trace listener (false); the 2nd parameter concerns the carriage return for WriteLine(), if it is set to true, the message sent to WriteLine will use a new line instead of being added to the current buffer. This happens when you use the Write() function. WriteLine() and Write() are the only functions with the override keyword.

using System.Diagnostics;

static void Main() 
    #if (DEBUG)
    // debug mode

    // release mode
    Application.Run(new Form1());

void MyFunction()
   float f=3.1415f;
   Debug.WriteLine("Output will only appear in Debug Mode");
   Trace.WriteLine("Output will appear in both Debug 
                   and Release mode" +   f.ToString());


This will immediately write the strings to the console and send them to the listeners (strings that you can visualize with an external tool like DebugView). The console is resizable now and I added an 'always on top' option.

The presence of the singleton also means you don't have to declare the object anywhere, these steps are automatically done by the class when you call Init(). The window is placed at the top-left corner of the screen. You can change the color of the ListView in the designer.

The timestamp uses the DateTime class of .NET, you can use this class to add a 'date' button, milliseconds...Feel free to improve it :)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

dake / calodox
Web Developer
France France
Student at the EPFL (Lausanne/Switzerland) in informatics. I have been coding since 1996 and I am member of the Swiss demogroup Calodox.

You may also be interested in...

Comments and Discussions

GeneralMake it thread dafe by add/change the following Pin
henryYYY10-Oct-07 12:04
memberhenryYYY10-Oct-07 12:04 
NewsDo it Threadsafe with BeginInvoke.... Pin
THaala17-Apr-07 10:30
memberTHaala17-Apr-07 10:30 
GeneralNext Gen VS 2005 Debug Console. Pin
riscy11-Aug-06 7:41
memberriscy11-Aug-06 7:41 
QuestionRe: Next Gen VS 2005 Debug Console. Pin
riscy12-Aug-06 23:33
memberriscy12-Aug-06 23:33 
AnswerRe: Next Gen VS 2005 Debug Console. Pin
Wolfgang G. Schmidt5-Feb-07 20:06
memberWolfgang G. Schmidt5-Feb-07 20:06 
GeneralRe: Next Gen VS 2005 Debug Console. Pin
riscy5-Feb-07 20:34
memberriscy5-Feb-07 20:34 
QuestionRe: Next Gen VS 2005 Debug Console. Pin
Marcus Deecke5-Jul-07 13:35
memberMarcus Deecke5-Jul-07 13:35 
GeneralLatest Build Pin
twesterd14-Apr-06 9:38
membertwesterd14-Apr-06 9:38 
GeneralThanks! Pin
hannahb4-Jul-05 7:38
memberhannahb4-Jul-05 7:38 
GeneralThreading problems Pin
stevz328-Nov-03 2:29
memberstevz328-Nov-03 2:29 
GeneralVery helpful Pin
Mark Focas26-Nov-03 12:11
memberMark Focas26-Nov-03 12:11 
GeneralSingleton & Namespace query Pin
Paul Evans14-May-03 3:23
memberPaul Evans14-May-03 3:23 
GeneralBIG MSG - My Changes to Your code Pin
Paul Evans14-May-03 5:26
memberPaul Evans14-May-03 5:26 
GeneralDebugConsole.Write Pin
Richard_D1-Sep-02 23:11
memberRichard_D1-Sep-02 23:11 
GeneralRe: DebugConsole.Write Pin
dake / calodox2-Sep-02 10:58
memberdake / calodox2-Sep-02 10:58 
GeneralRe: DebugConsole.Write Pin
Richard_D2-Sep-02 23:15
memberRichard_D2-Sep-02 23:15 
GeneralOutputDebugString Pin
Todd Smith1-Sep-02 5:15
memberTodd Smith1-Sep-02 5:15 
GeneralRe: OutputDebugString Pin
Joseph Dempsey1-Sep-02 6:27
memberJoseph Dempsey1-Sep-02 6:27 
GeneralRe: OutputDebugString Pin
dake / calodox1-Sep-02 8:30
memberdake / calodox1-Sep-02 8:30 
GeneralRe: OutputDebugString Pin
szurgot2-Sep-02 12:41
memberszurgot2-Sep-02 12:41 
GeneralRe: OutputDebugString Pin
dake / calodox3-Sep-02 10:04
memberdake / calodox3-Sep-02 10:04 

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
Web02 | 2.8.170525.1 | Last Updated 2 Sep 2002
Article Copyright 2002 by dake / calodox
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid