forked from psineur/MonoSublimeLogger
/
LoggerImpl.cs
executable file
·75 lines (65 loc) · 2.66 KB
/
LoggerImpl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace SublimeLogger
{
public class LoggerImpl : Logger
{
private int ErrorCount;
private int WarningCount;
private string ProjectDirectory = "";
public override void Initialize(IEventSource eventSource)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Sublime Text 2 output logger by Jacob Pennock");
eventSource.ProjectStarted += ProjectStarted;
eventSource.BuildFinished += BuildFinished;
eventSource.ErrorRaised += ErrorRaised;
eventSource.WarningRaised += WarningRaised;
ErrorCount = 0;
WarningCount = 0;
}
void ProjectStarted(object sender, ProjectStartedEventArgs e)
{
string directoryName = Path.GetDirectoryName(e.ProjectFile);
if (null != directoryName)
this.ProjectDirectory = directoryName;
// Console.WriteLine("Project Started: " + e.ProjectFile);
}
void BuildFinished(object sender, BuildFinishedEventArgs e)
{
Console.ForegroundColor = ConsoleColor.White;
if (e.Succeeded)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("Compilation SUCCEEDED! Errors:{0} Warnings:{1}",ErrorCount,WarningCount);
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("Compilation FAILED! Errors:{0} Warnings:{1}",ErrorCount,WarningCount);
}
Console.BackgroundColor = ConsoleColor.Black;
}
void ErrorRaised(object sender, BuildErrorEventArgs e)
{
string fullPath = Path.Combine(this.ProjectDirectory, e.File);
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("{0}({1},{2}) error:{3} {4}", fullPath, e.LineNumber, e.ColumnNumber, e.Code, e.Message);
Console.WriteLine();
ErrorCount++;
Console.ForegroundColor = ConsoleColor.White;
}
void WarningRaised(object sender, BuildWarningEventArgs e)
{
string fullPath = Path.Combine(this.ProjectDirectory, e.File);
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("{0}({1},{2}) warning:{3} {4}", fullPath, e.LineNumber, e.ColumnNumber, (e.Code != null) ? e.Code : "", e.Message);
Console.WriteLine();
WarningCount++;
Console.ForegroundColor = ConsoleColor.White;
}
}
}