microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

49lines · modepreview

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Teams.Common.Text;

namespace Microsoft.Teams.Common.Logging;

public enum LogLevel
{
    Error = 0,
    Warn = 1,
    Info = 2,
    Debug = 3
}

public static class LogLevelExtensions
{
    public static LogLevel? ToLogLevel(this string text)
    {
        return text.ToLower() switch
        {
            "error" => LogLevel.Error,
            "warn" => LogLevel.Warn,
            "info" => LogLevel.Info,
            "debug" => LogLevel.Debug,
            _ => null
        };
    }

    public static ANSI Color(this LogLevel level)
    {
        return level == LogLevel.Error ? ANSI.ForegroundRed
             : level == LogLevel.Warn ? ANSI.ForegroundYellow
             : level == LogLevel.Info ? ANSI.ForegroundCyan
             : ANSI.ForegroundMagenta;
    }

    public static string? ToString(this LogLevel level)
    {
        return level switch
        {
            LogLevel.Error => "error",
            LogLevel.Warn => "warn",
            LogLevel.Info => "info",
            LogLevel.Debug => "debug",
            _ => Enum.GetName(typeof(LogLevel), level)
        };
    }
}