Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Console.WriteLine within a Windows Forms application

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.

like image 614
ofer Avatar asked Dec 14 '08 09:12

ofer


People also ask

How do I show the console WriteLine in Visual Studio?

In Visual Studio uppermost menu choose Debug > Windows > Output. It shows all Console. WriteLine("Debug MyVariable: " + MyVariable) when you get to them.

What is the difference between Windows Forms application and console application?

A Windows form application is an application that has a graphical user interface(GUI) like the Visual C# IDE. A console program on the other hand is a text application. There are not fancy controls like buttons or textboxes in a console application and they are run from the command prompt.

What is use of console WriteLine () method?

Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.

How do I print from console WriteLine?

By using: \n – It prints new line. By using: \x0A or \xA (ASCII literal of \n) – It prints new line. By using: Console. WriteLine() – It prints new line.


1 Answers

Call Console.SetOut with a TextWriter you control (e.g. a StringWriter).

like image 82
Jon Skeet Avatar answered Sep 22 '22 12:09

Jon Skeet