Skip to content

Instantly share code, notes, and snippets.

@jhgbrt
Last active October 24, 2016 07:35
Show Gist options
  • Save jhgbrt/e220252f306415f17dc3 to your computer and use it in GitHub Desktop.
Save jhgbrt/e220252f306415f17dc3 to your computer and use it in GitHub Desktop.
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