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
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.
You could call AttachConsole WIN API function and then call this function using PInvoke:
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AttachConsole(uint dwProcessId);
const uint ATTACH_PARENT_PROCESS = 0x0ffffffff; // default value if not specifing a process ID
// Somewhere in main method
AttachConsole(ATTACH_PARENT_PROCESS);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With