microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
affd7569cfa8bd4a83b86066b8636721ea186364

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Common/Logging/LogLevel.cs

49lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Common.Text;
5
6namespace Microsoft.Teams.Common.Logging;
7
8public enum LogLevel
9{
10 Error = 0,
11 Warn = 1,
12 Info = 2,
13 Debug = 3
14}
15
16public static class LogLevelExtensions
17{
18 public static LogLevel? ToLogLevel(this string text)
19 {
20 return text.ToLower() switch
21 {
22 "error" => LogLevel.Error,
23 "warn" => LogLevel.Warn,
24 "info" => LogLevel.Info,
25 "debug" => LogLevel.Debug,
26 _ => null
27 };
28 }
29
30 public static ANSI Color(this LogLevel level)
31 {
32 return level == LogLevel.Error ? ANSI.ForegroundRed
33 : level == LogLevel.Warn ? ANSI.ForegroundYellow
34 : level == LogLevel.Info ? ANSI.ForegroundCyan
35 : ANSI.ForegroundMagenta;
36 }
37
38 public static string? ToString(this LogLevel level)
39 {
40 return level switch
41 {
42 LogLevel.Error => "error",
43 LogLevel.Warn => "warn",
44 LogLevel.Info => "info",
45 LogLevel.Debug => "debug",
46 _ => Enum.GetName(typeof(LogLevel), level)
47 };
48 }
49}