private static Level GetLevel(MySqlConnectorLogLevel level)
            {
                switch (level)
                {
                case MySqlConnectorLogLevel.Trace:
                    return(Level.Trace);

                case MySqlConnectorLogLevel.Debug:
                    return(Level.Debug);

                case MySqlConnectorLogLevel.Info:
                    return(Level.Info);

                case MySqlConnectorLogLevel.Warn:
                    return(Level.Warn);

                case MySqlConnectorLogLevel.Error:
                    return(Level.Error);

                case MySqlConnectorLogLevel.Fatal:
                    return(Level.Fatal);

                default:
                    throw new ArgumentOutOfRangeException(nameof(level), level, "Invalid value for 'level'.");
                }
            }
Exemplo n.º 2
0
            public void Log(MySqlConnectorLogLevel level, string message, object?[]?args = null, Exception?exception = null)
            {
                LogLevel logLevel = GetLevel(level);

                if (m_logger.IsEnabled(logLevel))
                {
                    m_logger.Log(s_loggerType, LogEventInfo.Create(logLevel, m_logger.Name, exception, CultureInfo.InvariantCulture, message, args));
                }
            }
Exemplo n.º 3
0
        public ConsoleLoggerProvider(MySqlConnectorLogLevel minimumLevel = MySqlConnectorLogLevel.Info, bool isColored = true)
        {
            if (minimumLevel < MySqlConnectorLogLevel.Trace || minimumLevel > MySqlConnectorLogLevel.Fatal)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumLevel), "minimumLevel must be between Trace and Fatal");
            }

            m_minimumLevel = minimumLevel;
            m_isColored    = isColored;
        }
 public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
 {
     if (args == null || args.Length == 0)
     {
         m_logger.Log(s_loggerType, GetLevel(level), message, exception);
     }
     else
     {
         m_logger.Log(s_loggerType, GetLevel(level), string.Format(CultureInfo.InvariantCulture, message, args), exception);
     }
 }
Exemplo n.º 5
0
 public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
 {
     if (args == null || args.Length == 0)
     {
         m_logger.Write(GetLevel(level), exception, message);
     }
     else
     {
         // rewrite message as template
         var template = tokenReplacer.Replace(message, "$1{MySql$2$3}$4");
         m_logger.Write(GetLevel(level), exception, template, args);
     }
 }
Exemplo n.º 6
0
            public void Log(MySqlConnectorLogLevel level, string message, object?[]?args = null, Exception?exception = null)
            {
                if (!IsEnabled(level))
                {
                    return;
                }

                var sb = new StringBuilder();

                sb.Append(s_levels[(int)level]);
                sb.Append('\t');
                sb.Append(m_name);
                sb.Append('\t');

                if (args is null || args.Length == 0)
                {
                    sb.Append(message);
                }
Exemplo n.º 7
0
            public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
            {
                if (!IsEnabled(level))
                {
                    return;
                }

                var sb = new StringBuilder();

                sb.Append(s_levels[(int)level]);
                sb.Append('\t');
                sb.Append(m_name);
                sb.Append('\t');

                if (args == null || args.Length == 0)
                {
                    sb.Append(message);
                }
                else
                {
                    sb.AppendFormat(CultureInfo.InvariantCulture, message, args);
                }
                sb.AppendLine();

                if (exception != null)
                {
                    sb.AppendLine(exception.ToString());
                }

                if (m_provider.m_isColored)
                {
                    lock (m_provider)
                    {
                        var oldColor = Console.ForegroundColor;
                        Console.ForegroundColor = s_colors[(int)level];
                        Console.Error.Write(sb.ToString());
                        Console.ForegroundColor = oldColor;
                    }
                }
                else
                {
                    Console.Error.Write(sb.ToString());
                }
            }
 /// <summary>
 /// Convert a <see cref="MySqlConnectorLogLevel"/> to a <see cref="LogEventLevel"/>
 /// </summary>
 /// <param name="level"></param>
 public static Maybe <LogEventLevel> ConvertToSerilogLevel(MySqlConnectorLogLevel level) =>
 level switch
 {
 public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
 {
     if (args is null || args.Length == 0)
     {
         m_logger.Write(GetLevel(level), exception, message);
     }
 public void Log(MySqlConnectorLogLevel level, string msg, object[] args, Exception exception = null)
 => s_logByLevel[level](_logger, exception, msg, args);
Exemplo n.º 11
0
 private static LogLevel GetLevel(MySqlConnectorLogLevel level) => level switch
 {
Exemplo n.º 12
0
 /// <summary>
 /// Ignores the specified log message.
 /// </summary>
 public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Returns <c>false</c>.
 /// </summary>
 public bool IsEnabled(MySqlConnectorLogLevel level) => false;
Exemplo n.º 14
0
 public bool IsEnabled(MySqlConnectorLogLevel level) => m_logger.IsEnabledFor(GetLevel(level));
Exemplo n.º 15
0
 public bool IsEnabled(MySqlConnectorLogLevel level) => level >= m_provider.m_minimumLevel && level <= MySqlConnectorLogLevel.Fatal;
Exemplo n.º 16
0
 public void Log(MySqlConnectorLogLevel level, string message, object?[]?args = null, Exception?exception = null)
 {
     if (args is null || args.Length == 0)
     {
         m_logger.Log(s_loggerType, GetLevel(level), message, exception);
     }
 public bool IsEnabled(MySqlConnectorLogLevel level) => s_isEnabledByLevel[level](_logger);