-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ConsoleLog.cs
54 lines (44 loc) · 1.68 KB
/
ConsoleLog.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.DotNet.ApiSymbolExtensions.Logging
{
/// <summary>
/// Class to define common logging abstraction to the console across the APICompat and GenAPI codebases.
/// </summary>
public class ConsoleLog : ILog
{
private readonly MessageImportance _messageImportance;
/// <inheritdoc />
public bool HasLoggedErrors { get; private set; }
public ConsoleLog(MessageImportance messageImportance) =>
_messageImportance = messageImportance;
/// <inheritdoc />
public virtual void LogError(string message)
{
HasLoggedErrors = true;
Console.Error.WriteLine(message);
}
/// <inheritdoc />
public virtual void LogError(string code, string message)
{
HasLoggedErrors = true;
Console.Error.WriteLine($"{code}: {message}");
}
/// <inheritdoc />
public virtual void LogWarning(string message) =>
Console.WriteLine(message);
/// <inheritdoc />
public virtual void LogWarning(string code, string message) =>
Console.WriteLine($"{code}: {message}");
/// <inheritdoc />
public virtual void LogMessage(string message) =>
LogMessage(MessageImportance.Normal, message);
/// <inheritdoc />
public virtual void LogMessage(MessageImportance importance, string message)
{
if (importance > _messageImportance)
return;
Console.WriteLine(message);
}
}
}