microsoft/TypeAgent

Public

mirrored fromhttps://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bf98bd2803fb2d2e1f8049afd9593160efeea581

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/autoShell/Logging/ConsoleLogger.cs

51lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System;
5
6namespace autoShell.Logging;
7
8/// <summary>
9/// Logger that writes all messages to the diagnostics output.
10/// Errors (red), warnings (yellow), and info (cyan) are written to stderr
11/// to prevent interleaving with JSON protocol responses on stdout.
12/// Debug messages are written to diagnostics output only.
13/// </summary>
14internal class ConsoleLogger : ILogger
15{
16 /// <inheritdoc/>
17 public void Error(Exception ex)
18 {
19 System.Diagnostics.Debug.WriteLine(ex);
20 ConsoleColor previousColor = Console.ForegroundColor;
21 Console.ForegroundColor = ConsoleColor.Red;
22 Console.Error.WriteLine("Error: " + ex.Message);
23 Console.ForegroundColor = previousColor;
24 }
25
26 /// <inheritdoc/>
27 public void Warning(string message)
28 {
29 System.Diagnostics.Debug.WriteLine(message);
30 ConsoleColor previousColor = Console.ForegroundColor;
31 Console.ForegroundColor = ConsoleColor.Yellow;
32 Console.Error.WriteLine("Warning: " + message);
33 Console.ForegroundColor = previousColor;
34 }
35
36 /// <inheritdoc/>
37 public void Info(string message)
38 {
39 System.Diagnostics.Debug.WriteLine(message);
40 ConsoleColor previousColor = Console.ForegroundColor;
41 Console.ForegroundColor = ConsoleColor.Cyan;
42 Console.Error.WriteLine("Info: " + message);
43 Console.ForegroundColor = previousColor;
44 }
45
46 /// <inheritdoc/>
47 public void Debug(string message)
48 {
49 System.Diagnostics.Debug.WriteLine(message);
50 }
51}
52