Created
June 25, 2017 22:09
-
-
Save thenameless314159/0ee59a60f560348fac1fc28bcd15861c to your computer and use it in GitHub Desktop.
Simple console color logger
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
/// <summary> | |
/// Simple console logger, this is basically a text formatter | |
/// </summary> | |
public class ConsoleLogger | |
{ | |
private static Dictionary<LogType, ConsoleColor> ColorWrapper { get; } | |
static ConsoleLogger() | |
{ | |
ColorWrapper = new Dictionary<LogType, ConsoleColor>() | |
{ | |
{ LogType.None, ConsoleColor.White }, | |
{ LogType.Info, ConsoleColor.White }, | |
{ LogType.Error, ConsoleColor.Magenta }, | |
{ LogType.Warning, ConsoleColor.Yellow }, | |
{ LogType.Debug, ConsoleColor.Green } | |
}; | |
} | |
public void LogMessage(string message, LogType loglevel) | |
{ | |
ForegroundColor = ColorWrapper[loglevel]; | |
WriteLine($"[{loglevel}] {message}"); | |
} | |
public void LogFromClass<T>(string message, LogType loglevel) | |
{ | |
ForegroundColor = ColorWrapper[loglevel]; | |
WriteLine($"[{loglevel}][{typeof(T).Name}] {message}"); | |
} | |
public void LogFromClass(string message, LogType loglevel, Type fromClass) | |
{ | |
ForegroundColor = ColorWrapper[loglevel]; | |
WriteLine($"[{loglevel}][{fromClass.Name}] {message}"); | |
} | |
public void LogFromClass(string message, LogType loglevel, object fromClass) | |
{ | |
ForegroundColor = ColorWrapper[loglevel]; | |
WriteLine($"[{loglevel}][{fromClass.GetType().Name}] {message}"); | |
} | |
public string GetInput() | |
{ | |
ForegroundColor = ConsoleColor.White; | |
Write("[Input] "); | |
return ReadLine(); | |
} | |
public string GetInput(string message) | |
{ | |
ForegroundColor = ConsoleColor.White; | |
WriteLine($"[Input] {message} "); | |
Write("> "); | |
return ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment