A Console window for Trace.WriteLine
-
Hi, I should like to write trace lines (using Trace.WriteLine or even Console.WriteLine) to a console window, but this time from a Class module. The class module does not create a Console (aka command line)window, so Console.WriteLine does not work. Neither could I find an example of specifying a (or creating a) console window for this kind of output. Anybody Any Idea how to do this? Tx Aad Aad Slingerland Zevenaar The Netherlands
-
Hi, I should like to write trace lines (using Trace.WriteLine or even Console.WriteLine) to a console window, but this time from a Class module. The class module does not create a Console (aka command line)window, so Console.WriteLine does not work. Neither could I find an example of specifying a (or creating a) console window for this kind of output. Anybody Any Idea how to do this? Tx Aad Aad Slingerland Zevenaar The Netherlands
Applications for either the console or windows subsystem won't display output for
Trace.WriteLine
unless you add the following lines of code before calling your firstTrace.WriteLine
(orDebug.WriteLine
):Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
To display a console window for a Windows Forms applcation compiled for the window subsystem (because a Windows Forms application can be compiled for the console subsystem and work, plus write console data; ildasm.exe is compiled this way) you'd have to P/Invoke
CreateConsoleScreenBuffer
and write aTextWriter
around that for use with theTextWriterTraceListener
, or just write your ownTraceListener
derivative to do that. The easiest is just compile your Windows Forms application using/t:exe
instead of/t:winexe
so that you already have a console attached to the process. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog] -
Applications for either the console or windows subsystem won't display output for
Trace.WriteLine
unless you add the following lines of code before calling your firstTrace.WriteLine
(orDebug.WriteLine
):Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
To display a console window for a Windows Forms applcation compiled for the window subsystem (because a Windows Forms application can be compiled for the console subsystem and work, plus write console data; ildasm.exe is compiled this way) you'd have to P/Invoke
CreateConsoleScreenBuffer
and write aTextWriter
around that for use with theTextWriterTraceListener
, or just write your ownTraceListener
derivative to do that. The easiest is just compile your Windows Forms application using/t:exe
instead of/t:winexe
so that you already have a console attached to the process. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]Hello Heath, I give this a try first thing in the morning. Be back... Tx Aad Aad Slingerland Zevenaar The Netherlands
-
Hi, I should like to write trace lines (using Trace.WriteLine or even Console.WriteLine) to a console window, but this time from a Class module. The class module does not create a Console (aka command line)window, so Console.WriteLine does not work. Neither could I find an example of specifying a (or creating a) console window for this kind of output. Anybody Any Idea how to do this? Tx Aad Aad Slingerland Zevenaar The Netherlands
Sound like you might be doing what I was doing. I kept writing Console harness apps to get the output to track what's going on while developing until I found out about
System.Diagnostics.Debug.WriteLine()
. If you're using .Net Studio, it will display the information in the Output window. I use it in both windows forms or special classes that have no GUI interface. Sure beat the heck out of the test harnesses. -
Sound like you might be doing what I was doing. I kept writing Console harness apps to get the output to track what's going on while developing until I found out about
System.Diagnostics.Debug.WriteLine()
. If you're using .Net Studio, it will display the information in the Output window. I use it in both windows forms or special classes that have no GUI interface. Sure beat the heck out of the test harnesses.Working on the subject I found a even simpler way to create a console window from within a class module. It requires two p/invoke functions from kernel32 and than Console.WriteLine () will do! It goes like this... bool b = AllocConsole (); Console.WriteLine ("This..."); Console.WriteLine ("...That"); bool b = FreeConsole (); Aad Aad Slingerland Zevenaar The Netherlands