Exemple #1
0
        private static LogLevel Map(Common.Logging.LogLevel level)
        {
            switch (level)
            {
            case Common.Logging.LogLevel.All:
                return(LogLevel.Trace);

            case Common.Logging.LogLevel.Debug:
                return(LogLevel.Debug);

            case Common.Logging.LogLevel.Error:
                return(LogLevel.Error);

            case Common.Logging.LogLevel.Fatal:
                return(LogLevel.Fatal);

            case Common.Logging.LogLevel.Info:
                return(LogLevel.Info);

            case Common.Logging.LogLevel.Trace:
                return(LogLevel.Trace);

            case Common.Logging.LogLevel.Warn:
                return(LogLevel.Warn);
            }

            throw new NotSupportedException("Unknown log level.");
        }
Exemple #2
0
        protected override void WriteInternal(LogLevel level, object message, Exception exception)
        {
            switch (level)
            {
            case LogLevel.Trace:
                Logger.LogTrace(ComputeStringMessageValue(message));
                break;

            case LogLevel.Debug:
                Logger.LogDebug(ComputeStringMessageValue(message));
                break;

            case LogLevel.Info:
                Logger.LogInformation(ComputeStringMessageValue(message));
                break;

            case LogLevel.Warn:
                Logger.LogWarning(exception, ComputeStringMessageValue(message));
                break;

            case LogLevel.Error:
                Logger.LogError(ComputeStringMessageValue(message));
                break;

            case LogLevel.Fatal:
                Logger.LogCritical(exception, ComputeStringMessageValue(message));
                break;

            case LogLevel.Off:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Writes a log message.
        /// </summary>
        /// <param name="level">
        ///   The log level for the message.
        /// </param>
        /// <param name="message">
        ///   The message.
        /// </param>
        /// <param name="exception">
        ///   The exception associated with the message.
        /// </param>
        protected override void WriteInternal(Common.Logging.LogLevel level, object message, Exception exception)
        {
            switch (level)
            {
            case Common.Logging.LogLevel.Trace:
                _logger.LogTrace(exception, Convert.ToString(message));
                break;

            case Common.Logging.LogLevel.Debug:
                _logger.LogDebug(exception, Convert.ToString(message));
                break;

            case Common.Logging.LogLevel.Info:
                _logger.LogInformation(exception, Convert.ToString(message));
                break;

            case Common.Logging.LogLevel.Error:
                _logger.LogError(exception, Convert.ToString(message));
                break;

            case Common.Logging.LogLevel.Fatal:
                _logger.LogCritical(exception, Convert.ToString(message));
                break;

            default:
                _logger.LogDebug(exception, Convert.ToString(message));
                break;
            }
        }
        public static Level ConvertLogLevel(Common.Logging.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case Common.Logging.LogLevel.All:
                return(Level.All);

            case Common.Logging.LogLevel.Debug:
                return(Level.Debug);

            case Common.Logging.LogLevel.Error:
                return(Level.Error);

            case Common.Logging.LogLevel.Fatal:
                return(Level.Fatal);

            case Common.Logging.LogLevel.Info:
                return(Level.Info);

            case Common.Logging.LogLevel.Off:
                return(Level.Off);

            case Common.Logging.LogLevel.Trace:
                return(Level.Trace);

            case Common.Logging.LogLevel.Warn:
                return(Level.Warn);

            default:
                throw new NotSupportedException("Not Supported logLevel:" + logLevel.ToString());
            }
        }
Exemple #5
0
        /// <summary>
        /// Commons.Logging中的日誌級別與NLog中的日誌級別對應關係設置
        /// </summary>
        /// <param name="logLevel">Commons.Logging中的日誌級別</param>
        /// <returns>自定義日誌級別</returns>
        /// <remarks>
        /// Commons.Logging
        ///		OFF > FATAL > ERROR > WARN > INFO > DEBUG  > TRACE  > ALL
        /// NLog
        ///		OFF > FATAL > ERROR > WARN > INFO > DEBUG  >   >   > TRACE
        /// </remarks>
        private static LogLevel GetLevel(Common.Logging.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case Common.Logging.LogLevel.All:
                return(LogLevel.Trace);

            case Common.Logging.LogLevel.Trace:
                return(LogLevel.Trace);

            case Common.Logging.LogLevel.Debug:
                return(LogLevel.Debug);

            case Common.Logging.LogLevel.Info:
                return(LogLevel.Info);

            case Common.Logging.LogLevel.Warn:
                return(LogLevel.Warn);

            case Common.Logging.LogLevel.Error:
                return(LogLevel.Error);

            case Common.Logging.LogLevel.Fatal:
                return(LogLevel.Fatal);

            case Common.Logging.LogLevel.Off:
                return(LogLevel.Off);

            default:
                throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, MessageUtil.GetMessage(() => MsgResources.E0038L));
            }
        }
Exemple #6
0
        /// <summary>
        /// 消息寫入日誌的詳細處理
        /// </summary>
        /// <param name="logLevel">日誌處理級別</param>
        /// <param name="message">日誌信息<see cref="ILogContext"/>自定義的屬性消息,寫入到<see cref="LogEventInfo.Properties"/></param>
        /// <param name="exception">異常對象</param>
        protected override void WriteInternal(Common.Logging.LogLevel logLevel, object message, Exception exception)
        {
            LogLevel     level       = GetLevel(logLevel);
            ILogContext  context     = message as ILogContext;
            object       messageText = context == null ? message : context.Message;
            LogEventInfo logEvent    = new LogEventInfo(level, _logger.Name, null, "{0}", new object[1] {
                messageText
            }, exception);

            context?.Properties.ToList().ForEach(logEvent.Properties.Add);
            StackTrace st    = new StackTrace(0);
            int        index = 0;

            StackFrame[] frames = st.GetFrames();
            foreach (StackFrame sf in frames)
            {
                MethodBase mb = sf.GetMethod();
                Type       dt = mb.DeclaringType;
                if (dt == null || ExcludeTypes.Contains(dt) || ExcludeAssemblies.Contains(dt.Assembly) || ExcludeNameSpaces.Contains(dt.Namespace))
                {
                    index++;
                    continue;
                }
                logEvent.SetStackTrace(st, index);
                break;
            }
            _logger.Log(GetType(), logEvent);
        }
Exemple #7
0
        protected override void WriteInternal(Common.Logging.LogLevel level, object message, Exception exception)
        {
            if (level == Common.Logging.LogLevel.Off)
            {
                return;
            }

            _log.Log(Map(level), () => message == null ? null : message.ToString(), exception);
        }
Exemple #8
0
        protected override void WriteInternal(LogLevel level, object message, Exception exception)
        {
            switch (level)
            {
            case LogLevel.All:
                _logger.Debug(message.ToString);
                break;

            case LogLevel.Debug:
                _logger.Debug(message.ToString);
                break;

            case LogLevel.Error:
                if (exception == null)
                {
                    _logger.Error(message.ToString());
                }
                else
                {
                    _logger.Error(exception, message.ToString());
                }
                break;

            case LogLevel.Fatal:
                if (exception == null)
                {
                    _logger.Error(message.ToString());
                }
                else
                {
                    _logger.Error(exception, message.ToString());
                }
                break;

            case LogLevel.Off:
                break;

            case LogLevel.Trace:
                _logger.Debug(message.ToString);
                break;

            case LogLevel.Warn:
                _logger.Warn(message.ToString());
                break;

            case LogLevel.Info:
                _logger.Info(message.ToString());
                break;

            default:
                _logger.Info(message.ToString());
                break;
            }
        }
        protected override void WriteInternal(LogLevel level, object message, Exception exception)
        {
            var textMessage = message?.ToString();

            if (textMessage == null && exception == null)
            {
                textMessage = string.Empty;
            }

            switch (level)
            {
            case LogLevel.All:
            case LogLevel.Trace:
                _lykkeLog.Trace(LoggerName, textMessage, exception: exception);
                break;

            case LogLevel.Debug:
                _lykkeLog.Debug(LoggerName, textMessage, exception: exception);
                break;

            case LogLevel.Info:
                _lykkeLog.Info(LoggerName, textMessage, exception: exception);
                break;

            case LogLevel.Warn:
                _lykkeLog.Warning(LoggerName, textMessage, exception);
                break;

            case LogLevel.Error:
                _lykkeLog.Error(LoggerName, exception, textMessage);
                break;

            case LogLevel.Fatal:
                _lykkeLog.Critical(LoggerName, exception, textMessage);
                break;

            case LogLevel.Off:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, "Unexpected nethereum log level");
            }
        }
        public static NethereumLog CreateNethereumLog <TComponent>(this ILogFactory logFactory, TComponent component, LogLevel logLevel = LogLevel.All)
        {
            if (logFactory == null)
            {
                throw new ArgumentNullException(nameof(logFactory));
            }

            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            var lykkeLog = logFactory.CreateLog(component);

            return(new NethereumLog(lykkeLog, logLevel));
        }
Exemple #11
0
 protected override void WriteInternal(LogLevel level, object message, Exception exception)
 {
     _logger.Log(Levels[level], message.ToString());
 }
Exemple #12
0
 public DotNetCoreLogger(string logName, LogLevel logLevel, bool showlevel, bool showDateTime, bool showLogName, string dateTimeFormat) : base(logName, logLevel, showlevel, showDateTime, showLogName, dateTimeFormat)
 {
 }
Exemple #13
0
 public QuartzLogger(LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat = "o")
     : base("SQLoogleBot", level, showLevel, showDateTime, showLogName, dateTimeFormat)
 {
     _logger = LogManager.GetLogger("SQLoogleBot");
 }
 public NethereumLog(ILykkeLog lykkeLog, LogLevel logLevel = LogLevel.All)
 {
     _logLevel = logLevel;
     _lykkeLog = lykkeLog;
 }