Last active
October 24, 2016 07:35
-
-
Save jhgbrt/e220252f306415f17dc3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.IO; | |
namespace Tools.Infrastructure | |
{ | |
class Logger | |
{ | |
static object _lock = new object(); | |
public static void Info(string message) | |
{ | |
Log(Console.ForegroundColor, Console.Out, message); | |
} | |
public static void Warn(string message) | |
{ | |
Log(ConsoleColor.DarkYellow, Console.Out, message); | |
} | |
public static void Error(string message) | |
{ | |
Log(ConsoleColor.DarkRed, Console.Error, message); | |
} | |
private static void Log(ConsoleColor foregroundColor, TextWriter writer, string message) | |
{ | |
var originalColor = Console.ForegroundColor; | |
lock (_lock) | |
try | |
{ | |
Console.ForegroundColor = foregroundColor; | |
writer.WriteLine(message); | |
} | |
finally | |
{ | |
Console.ForegroundColor = originalColor; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment