Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write color text to the Visual Studio output window from c#?

I want to write color text to the Visual Studio output window from c#. I want to output red code from my unit tests.

like image 713
AnthonyLambert Avatar asked Mar 11 '10 16:03

AnthonyLambert


2 Answers

I found this question while trying to figure out why some of the lines of text in my Visual Studio 2017 Output window are colored red, and how I could accomplish the same thing.

I found that I was able to get red text by writing out a line which included:

  • an instance of "Error:" (Error, colon, followed by a space)
  • (other characters can go here)
  • another instance of "Error:" (Error, colon, followed by a space)
  • (other characters can go here)
  • followed by 1 instance of "Error *" (Error, followed by a space and then some other character)
  • (other characters can go here)

An example:

Debug.WriteLine("Error: This line will be red Error: Error Jeff");
like image 190
Jeff Roe Avatar answered Oct 26 '22 07:10

Jeff Roe


In addition to Jeff Roe I've managed to get this:

Warnings: Console.WriteLine($"Warning: Warning '{message}'");

Errors: Console.WriteLine($"Error: Error '{message}'");

enter image description here

Sadly I could not figure out how to get green output. If any1 could add this I would be super happy !

like image 6
Felix D. Avatar answered Oct 26 '22 05:10

Felix D.