microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0-preview.5

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

46lines · modecode

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