-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConsoleLogAdapter.cs
More file actions
43 lines (36 loc) · 1.48 KB
/
ConsoleLogAdapter.cs
File metadata and controls
43 lines (36 loc) · 1.48 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
using System;
using System.IO;
using ApiCodeGenerator.Abstraction;
namespace ApiCodeGenerator.MSBuild
{
internal class ConsoleLogAdapter : ILogger
{
public void LogError(string? code, string? sourceFile, string message, params object[] messageArgs)
=> Log(Console.Error, "error", code, sourceFile, string.Format(message, messageArgs));
public void LogMessage(string? code, string? sourceFile, string message, params object[] messageArgs)
=> Log(Console.Out, code is null ? null : "info", code, sourceFile, string.Format(message, messageArgs));
public void LogWarning(string? code, string? sourceFile, string message, params object[] messageArgs)
=> Log(Console.Out, "warning", code, sourceFile, string.Format(message, messageArgs));
private static void Log(TextWriter writer, string? type, string? code, string? file, string message)
{
if (file is not null)
{
writer.Write(Path.IsPathFullyQualified(file)
? file
: Path.GetFullPath(file));
writer.Write("(1,1): ");
}
if (type is not null)
{
writer.Write(type);
if (code is not null)
{
writer.Write(" ");
writer.Write(code);
}
writer.Write(": ");
}
writer.WriteLine(message);
}
}
}