views:

293

answers:

4

Is it possible in C# to see the traces in a separate console. For example, I am having a window based application in which there are trace statements that will write the currently executed method name in to the console. When I run this application, it should automatically open a console and start the traces. Is this possible?

+3  A: 

If you set the project type of your window application to Console, it will open a console window when you run it.

John
But can this be configured in the run time. I mean is there any possibility for me to run the application with some debug switches (say Foo.exe -debug something like this) so that it will open a new terminal window that can trace log the messages ??
+2  A: 

I think you are looking for a TraceListener class. (another link)

In .NET you use a TraceListener to listen to your own trace message. And then you can print them out in a form with textbox or a console window.

Listeners can also be configured via app.config if my memory serves me right. That's so you could debug deployed applications.

chakrit
But if I use a ConsoleTracer for a Window Application, there won't be any effect until I do what John has told me, correct ??
You need it in a Console window only? A custom window wont do?
chakrit
Hmm. I wanna have those traces in a console. I think it will be better, if possible
+3  A: 

You can create a console window by calling the Win32 AllocConsole API through P/Invoke.

http://pinvoke.net/default.aspx/kernel32/AllocConsole.html

James Curran
A: 

I'd recommend dbgview.exe from Sysinternals. It allows you to capture your trace output and save it to file (among other features).

You can get it from http://live.sysinternals.com

Philipp Schmid