Exemple #1
0
        private static Microsoft.Extensions.Logging.LogLevel ToTargetLogLevel(LogLevel logLevel)
        {
            switch (logLevel)
            {
            case LogLevel.Trace:
                return(Microsoft.Extensions.Logging.LogLevel.Trace);

            case LogLevel.Debug:
                return(Microsoft.Extensions.Logging.LogLevel.Debug);

            case LogLevel.Info:
                return(Microsoft.Extensions.Logging.LogLevel.Information);

            case LogLevel.Warn:
                return(Microsoft.Extensions.Logging.LogLevel.Warning);

            case LogLevel.Error:
                return(Microsoft.Extensions.Logging.LogLevel.Error);

            case LogLevel.Fatal:
                return(Microsoft.Extensions.Logging.LogLevel.Critical);
            }

            return(Microsoft.Extensions.Logging.LogLevel.None);
        }
        /// <summary>
        /// Returns the system log level corresponding to a Hangfire log level.
        /// </summary>
        private static SystemLogLevel GetSystemLogLevel(HangfireLogLevel logLevel)
        {
            switch (logLevel)
            {
                case HangfireLogLevel.Debug:
                    return SystemLogLevel.Debug;

                case HangfireLogLevel.Trace:
                    return SystemLogLevel.Trace;

                case HangfireLogLevel.Info:
                    return SystemLogLevel.Information;

                case HangfireLogLevel.Warn:
                    return SystemLogLevel.Warning;

                case HangfireLogLevel.Error:
                    return SystemLogLevel.Error;

                case HangfireLogLevel.Fatal:
                    return SystemLogLevel.Critical;

                default:
                    throw new ArgumentOutOfRangeException(nameof(logLevel));
            }
        }
 public bool Log(
     LogLevel logLevel, Func <string> messageFunc, Exception exception = null)
 {
     if (messageFunc != null && logLevel >= LogLevel.Info)
     {
         _logger.Log(TranslateLevel(logLevel), exception, messageFunc());
     }
     return(true);
 }
        /// <summary>
        /// Logs a message from Hangfire.
        /// </summary>
        public bool Log(HangfireLogLevel logLevel, Func<string> messageFunc, Exception exception = null)
        {
            var systemLogLevel = GetSystemLogLevel(logLevel);

            if (!_logger.IsEnabled(systemLogLevel))
                return false;

            var message = messageFunc != null ? messageFunc() : string.Empty;

            _logger.Log(GetSystemLogLevel(logLevel), 0, message, exception, MessageFormatter);

            return true;
        }
Exemple #5
0
        public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception = null)
        {
            var targetLogLevel = ToTargetLogLevel(logLevel);

            // When messageFunc is null, Hangfire.Logging
            // just determines is logging enabled.
            if (messageFunc == null)
            {
                return(_targetLogger.IsEnabled(targetLogLevel));
            }

            _targetLogger.Log(targetLogLevel, 0, CreateStateObject(messageFunc()), exception, MessageFormatterFunc);
            return(true);
        }
        public bool Log(Hangfire.Logging.LogLevel logLevel, Func <string> messageFunc, Exception exception = null)
        {
            try
            {
                string message = messageFunc != null?messageFunc() : string.Empty;

                if (!string.IsNullOrEmpty(message))
                {
                    switch (logLevel)
                    {
                    case Hangfire.Logging.LogLevel.Trace:
                    case Hangfire.Logging.LogLevel.Debug:
                    case Hangfire.Logging.LogLevel.Info:
                    {
                        this.logService.Debug(message);
                    } break;

                    case Hangfire.Logging.LogLevel.Warn:
                    {
                        this.logService.Debug(message);
                    } break;

                    case Hangfire.Logging.LogLevel.Error:
                    case Hangfire.Logging.LogLevel.Fatal:
                    {
                        this.logService.Error(message);
                    } break;
                    }
                }

                if (exception != null)
                {
                    this.logService.Error(exception);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #7
0
 public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception)
 {
     return(false);
 }