private static LogLevel ToLogLevel(MigrationLogLevel level)
        {
            switch (level)
            {
            case MigrationLogLevel.None:
                return(LogLevel.None);

            case MigrationLogLevel.Trace:
                return(LogLevel.Trace);

            case MigrationLogLevel.Debug:
                return(LogLevel.Debug);

            case MigrationLogLevel.Information:
                return(LogLevel.Information);

            case MigrationLogLevel.Warning:
                return(LogLevel.Warning);

            case MigrationLogLevel.Error:
                return(LogLevel.Error);

            case MigrationLogLevel.Fatal:
                return(LogLevel.Critical);

            default:
                return(LogLevel.None);
            }
        }
        /// <summary>
        /// Log by level.
        /// </summary>
        /// <param name="level"></param>
        /// <param name="exception"></param>
        /// <param name="messageFormat"></param>
        /// <param name="args"></param>
        public void Log(MigrationLogLevel level, Exception exception, string messageFormat, params string[] args)
        {
            switch (level)
            {
            case MigrationLogLevel.None:
                return;

            case MigrationLogLevel.Trace:
                if (_logger.IsEnabled(LogLevel.Trace))
                {
                    _logger.LogTrace(0, exception, messageFormat, ToObjectArray(args));
                }
                return;

            case MigrationLogLevel.Debug:
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug(0, exception, messageFormat, ToObjectArray(args));
                }
                return;

            case MigrationLogLevel.Information:
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation(0, exception, messageFormat, ToObjectArray(args));
                }
                return;

            case MigrationLogLevel.Warning:
                if (_logger.IsEnabled(LogLevel.Warning))
                {
                    _logger.LogWarning(0, exception, messageFormat, ToObjectArray(args));
                }
                return;

            case MigrationLogLevel.Error:
                if (_logger.IsEnabled(LogLevel.Error))
                {
                    _logger.LogError(0, exception, messageFormat, ToObjectArray(args));
                }
                return;

            case MigrationLogLevel.Fatal:
                if (_logger.IsEnabled(LogLevel.Critical))
                {
                    _logger.LogCritical(0, exception, messageFormat, ToObjectArray(args));
                }
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, null);
            }
        }
 /// <inheritdoc />
 public bool IsEnabled(MigrationLogLevel level) => false;
 /// <inheritdoc />
 public void Log(MigrationLogLevel level, Exception exception, string messageFormat, params string[] args)
 {
 }
 /// <summary>
 /// Check if the log level is enabled.
 /// </summary>
 /// <param name="level"></param>
 /// <returns></returns>
 public bool IsEnabled(MigrationLogLevel level) =>
 _logger.IsEnabled(ToLogLevel(level));
Esempio n. 6
0
 /// <summary>
 /// Logs the given log entry
 /// </summary>
 /// <param name="logger">The logger instance</param>
 /// <param name="level">The log level</param>
 /// <param name="exception">An optional exception</param>
 /// <param name="messageFormat">The message format</param>
 public static void Log(this IMigrationLogger logger, MigrationLogLevel level, Exception exception, string messageFormat) =>
 logger.Log(level, exception, messageFormat);