Created
December 31, 2014 11:36
-
-
Save kasuken/f1b5f787226c0c2e3c02 to your computer and use it in GitHub Desktop.
An helper to log in a console application with colors and log level priority
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class LogHelper | |
{ | |
enum LogLevel | |
{ | |
Debug, | |
Info, | |
Warning, | |
Error | |
} | |
public static void LogDebug(string message) | |
{ | |
ConsoleLog(LogLevel.Debug, message); | |
} | |
public static void LogInfo(string message) | |
{ | |
ConsoleLog(LogLevel.Info, message); | |
} | |
public static void LogWarning(string message) | |
{ | |
ConsoleLog(LogLevel.Warning, message); | |
} | |
public static void LogError(string message) | |
{ | |
ConsoleLog(LogLevel.Error, message); | |
} | |
private static void ConsoleLog(LogLevel logLevel, string message) | |
{ | |
switch (logLevel) | |
{ | |
case LogLevel.Debug: | |
Console.ForegroundColor = ConsoleColor.White; | |
break; | |
case LogLevel.Info: | |
Console.ForegroundColor = ConsoleColor.Green; | |
break; | |
case LogLevel.Warning: | |
Console.ForegroundColor = ConsoleColor.Yellow; | |
break; | |
case LogLevel.Error: | |
Console.ForegroundColor = ConsoleColor.Red; | |
break; | |
} | |
Console.WriteLine(message); | |
Console.ResetColor(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment