Search code examples
c++mfcconsoleapp-configtrace

Trace to Console in MFC application


I am currently tracing my errors in an MFC application to a .log file and to the event viewer, but I would also like to trace to the console. A console solution is posted here: http://www.codeproject.com/Articles/612/Creating-a-console-for-your-MFC-app-s-debug-output

but I want to be able to turn it on and off easily (Perhaps with a TraceSwitch).


Solution

  • In addition to the obvious,

    <add name="LPRConsoleListener" type=System.Diagnostics.ConsoleTraceListener" />
    

    You must put

    AllocConsole()
    

    in your InitInstance() function before you initialize your MFC Window.