I have an external DLL whose source code is C#. From the documentation for the DLL, I determined that it writes its debug messages to the console using Console.WriteLine
.
I'd like to use this DLL within a WinForms application. However, what I have discovered is that I cannot see the debug messages emitted by the DLL since a WinForms application does not have a console.
is there a way to capture those debug messages, perhaps even to a simple log file? Of course, using ProcessInfo.RedirectStandartOutput
will not work as I do not use the DLL as a process.
You would be best served using the System.Diagnostics namespace and Debug.WriteLine instead. Debug supports 'listeners' that can be added at run-time or via the app/web.config files. For example:-
If you implement any custom debug logging as a trace listener, you can capture your trace messages application wide very easily.
Call Console.SetOut with a TextWriter you control (e.g. a StringWriter).