How can i add a console output to a windows wpf application C#

Bayo Alen picture Bayo Alen · Sep 26, 2011 · Viewed 8.5k times · Source

i would like to add an additional console window to log realtine info from my wpf application. Any idea??

Bayo

answer: console application in the project properties works for me. thank's

Answer

yas4891 picture yas4891 · Sep 26, 2011

Don't do it.

Take a look at log4net or NLog for log output into a file. With the right configuration of those frameworks you get a lot more power (different log levels, automatic timestamps, automatic class names in front of every logged line)

And while you are at it, you might also want to implement a facade of your own, to hide the used logging framework from the rest of your code. This would allow you to easily change the logging framework, if and when the need arises.


If you want to have both a console and a GUI window for your program, you could implement this behaviour by compiling the project as console application (csc /target:exe). But beware: This most certainly leads to bad usability, because no user would expect your app to have both a console and a GUI window.