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;
}
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With