I’ve had several WPF projects which required showing a log window. The idea is to log a constant stream of status messages for a admin to monitor. You could write your own LogWindow and pass messages into the window but there is an easier way. Tell your WPF application to run as a ‘Console’ application.
Now this sounds funny but it is easy to do and doesn’t impact your WPF application.
- Right click the Project Properties node in the Solution explorer or choose the Project menu.
- Change the project Application Type to ‘WPF Console Application.
Run the application, you will see two windows; the main WPF window and the console window.
To write to the console window use Console.Write or Console.WriteLine. You can also control the size and position of the window and change the font color.
1: Console.SetWindowSize(40, 20)2: Console.SetWindowPosition(0, 0)3: Console.Title = "Log Window"4:5: Console.ForegroundColor = ConsoleColor.Yellow6: Console.WriteLine("Log: Something happened")7: Console.ForegroundColor = ConsoleColor.Red8: Console.WriteLine("Details: Database initialized")