Created
May 14, 2015 18:51
-
-
Save igoravl/0e95a252ad4876551403 to your computer and use it in GitHub Desktop.
Color-aware custom MSBuild 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
// 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