Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No output to console from a WPF application?

Tags:

c#

.net

console

wpf

I'm using Console.WriteLine() from a very simple WPF test application, but when I execute the application from the command line, I'm seeing nothing being written to the console. Does anyone know what might be going on here?

I can reproduce it by creating a WPF application in VS 2008, and simply adding Console.WriteLine("text") anywhere where it gets executed. Any ideas?

All I need for right now is something as simple as Console.WriteLine(). I realize I could use log4net or somet other logging solution, but I really don't need that much functionality for this application.

Edit: I should have remembered that Console.WriteLine() is for console applications. Oh well, no stupid questions, right? :-) I'll just use System.Diagnostics.Trace.WriteLine() and DebugView for now.

like image 601
Rob Avatar asked Oct 02 '08 02:10

Rob


2 Answers

You can use

Trace.WriteLine("text");

This will output to the "Output" window in Visual Studio (when debugging).

make sure to have the Diagnostics assembly included:

using System.Diagnostics;
like image 74
Phobis Avatar answered Nov 01 '22 18:11

Phobis


Right click on the project, "Properties", "Application" tab, change "Output Type" to "Console Application", and then it will also have a console.

like image 146
Brian Avatar answered Nov 01 '22 16:11

Brian