Thursday, July 17, 2014

Console Messaging: Error, Warning, Colored Text etc.

Here are some methods, I used in my Console applications to show Errors, Warnings, or simple colorful Text:

private static void ConsoleWrite(string FormattedString, ConsoleColor TextColor)
{
	ConsoleColor curColor = Console.ForegroundColor;
	Console.ForegroundColor = TextColor;
	Console.WriteLine(FormattedString);
	Console.ForegroundColor = curColor; //Restoring original console foreground color.
}
private static void ShowError(string FormattedString)
{
	ConsoleWrite(FormattedString, ConsoleColor.Red);
}
private static void ShowSuccess(string FormattedString)
{
	ConsoleWrite(FormattedString, ConsoleColor.Green);
}
private static void ShowWarning(string FormattedString)
{
	ConsoleWrite(FormattedString, ConsoleColor.DarkYellow);
}

No comments: