How to change Foreground Color of Text in Console
As we know in .NET Core all types of applications will run on Console based and in some situations like to identify monitoring different category level debug information it would be great each category information can be displayed with different foreground color for better readability.
Following is the sample code where we can change the Console based text in different colors as configured.
public static void Main(string[] args) { // Display current Foreground color Console.WriteLine("Text in Default Foreground Color: {0}", Console.ForegroundColor); // Set the Foreground color to blue Console.ForegroundColor = ConsoleColor.Blue; // Display current Foreground color Console.WriteLine("Text in Blue Foreground Color: {0}", Console.ForegroundColor); // Set the Foreground color to green Console.ForegroundColor = ConsoleColor.Green; // Display current Foreground color Console.WriteLine("Text in Green Foreground Color: {0}", Console.ForegroundColor); Console.ReadKey(); }
Following is the output of the above code