Skip to content

Instantly share code, notes, and snippets.

@igoravl
Created May 14, 2015 18:51
Show Gist options
  • Save igoravl/0e95a252ad4876551403 to your computer and use it in GitHub Desktop.
Save igoravl/0e95a252ad4876551403 to your computer and use it in GitHub Desktop.
Color-aware custom MSBuild logger
// NOTE: You must reference the assemblies Microsoft.Build.dll and Microsoft.Build.Framework.dll
// Both can be tipically found in C:\Program Files (x86)\MSBuild\<VS version>\bin
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
namespace ColorAwareMSBuildLogger
{
public class Logger : ConsoleLogger
{
public Logger()
: this(LoggerVerbosity.Normal)
{
}
public Logger(LoggerVerbosity verbosity)
: base(verbosity, GetWriteHandler(), GetColorSetter(), GetColorResetter())
{
}
private static WriteHandler GetWriteHandler()
{
return Console.Out.Write;
}
private static ColorSetter GetColorSetter()
{
return SetColor;
}
private static ColorResetter GetColorResetter()
{
return ResetColor;
}
protected static void SetColor(ConsoleColor color)
{
GetWriteHandler()(string.Format("[Color Change: {0}]", color));
}
protected static void ResetColor()
{
GetWriteHandler()(string.Format("[Color Reset]"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment