microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Common/Logging/LogLevel.cs
46lines · modecode
| 1 | using Microsoft.Teams.Common.Text; |
| 2 | |
| 3 | namespace Microsoft.Teams.Common.Logging; |
| 4 | |
| 5 | public enum LogLevel |
| 6 | { |
| 7 | Error = 0, |
| 8 | Warn = 1, |
| 9 | Info = 2, |
| 10 | Debug = 3 |
| 11 | } |
| 12 | |
| 13 | public 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 | } |