Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing color in Visual Studio Debug Console With Code

All right, I've inherited some code and the guy who started writing the code has a bad habit of squelching exceptions, thus making my life difficult. So as I look through the code I'm trying to toss something in the catch blocks so I can figure out what's going on. Since this is a Windows Forms application, I cannot write to the console itself, however I can write to the Debug console. I'd like to change the text foreground color when I hit one of these (previously) squelched exceptions so that I can easily pick them out as I debug. Of course, the other reason for writing to the debug console is so that the customer does not see these messages in the final design. Is there any way to do this? I've tried the following code, but it does not quite do it.

catch 
     {
        ConsoleColor tempColor = Console.ForegroundColor;
        StackTrace stackTrace = new StackTrace();
        Console.ForegroundColor = ConsoleColor.Red;
        System.Diagnostics.Debug.WriteLine("Exception Thrown: " + stackTrace.GetFrame(0).GetMethod().ToString());
        Console.ForegroundColor = tempColor;
     }
like image 694
audiFanatic Avatar asked Jun 10 '14 17:06

audiFanatic


1 Answers

Its may be too late but there is a Tool (which I have not tried :( ) https://marketplace.visualstudio.com/items?itemName=MikeWard-AnnArbor.VSColorOutput

I use http:// prefix to get my debug.writeline messages colored.

Debug.WriteLine("http://MyMessage")
like image 107
Timur Avatar answered Sep 26 '22 02:09

Timur