forked from SharpGenTools/SharpGenTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSBuildSharpGenLogger.cs
More file actions
55 lines (49 loc) · 1.78 KB
/
Copy pathMSBuildSharpGenLogger.cs
File metadata and controls
55 lines (49 loc) · 1.78 KB
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
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using SharpGen.Logging;
using ILogger = SharpGen.Logging.ILogger;
namespace SharpGenTools.Sdk;
internal sealed class MSBuildSharpGenLogger : ILogger
{
private readonly TaskLoggingHelper log;
public MSBuildSharpGenLogger(TaskLoggingHelper log)
{
this.log = log;
}
public void Exit(string reason, int exitCode)
{
log.LogError(reason ?? "");
throw new CodeGenFailedException(reason ?? "");
}
public void Log(LogLevel logLevel, LogLocation logLocation, string context, string code, string message, Exception exception, params object[] parameters)
{
if (message == null)
{
return;
}
switch (logLevel)
{
case LogLevel.Info:
log.LogMessage(context, code, null, logLocation?.File, logLocation?.Line ?? 0, logLocation?.Column ?? 0, 0, 0, MessageImportance.Normal, message, parameters);
break;
case LogLevel.Warning:
log.LogWarning(context, code, null, logLocation?.File, logLocation?.Line ?? 0, logLocation?.Column ?? 0, 0, 0, message, parameters);
if (exception != null)
{
log.LogWarningFromException(exception);
}
break;
case LogLevel.Error:
case LogLevel.Fatal:
log.LogError(context, code, null, logLocation?.File, logLocation?.Line ?? 0, logLocation?.Column ?? 0, 0, 0, message, parameters);
if (exception != null)
{
log.LogErrorFromException(exception, true, true, null);
}
break;
default:
break;
}
}
}