/// <summary>
        /// 将消息与异常写入到存储设备里
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="msg">消息</param>
        /// <param name="ex">异常</param>
        /// <param name="source">来源</param>
        /// <param name="tags">标签</param>
        protected override void WriteStorage(string level, string msg, Exception ex = null, string source = null, params string[] tags)
        {
            if (string.IsNullOrWhiteSpace(source) && ex != null)
            {
                source = ex.Source;
            }
            var logger = string.IsNullOrWhiteSpace(source) || name.Equals(source) ? nlog : NLog.LogManager.GetLogger(source);

            msg += " 标签:" + string.Join(",", AppendLocalIdTags(tags));

            var levelEnum = LogLevelHelper.Parse(level);

            switch (levelEnum)
            {
            case LogLevelEnum.TRACE:
                logger.Trace(ex, msg);

                break;

            case LogLevelEnum.DEBUG:
                logger.Debug(ex, msg);

                break;

            case LogLevelEnum.INFO:
                logger.Info(ex, msg);

                break;

            case LogLevelEnum.WRAN:
                logger.Warn(ex, msg);

                break;

            case LogLevelEnum.ERROR:
                logger.Error(ex, msg);

                break;

            case LogLevelEnum.FATAL:
                logger.Fatal(ex, msg);

                break;
            }
        }
        /// <summary>
        /// 将消息与异常写入到存储设备里
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="msg">消息</param>
        /// <param name="ex">异常</param>
        /// <param name="source">来源</param>
        /// <param name="tags">标签</param>
        protected override void WriteStorage(string level, string msg, Exception ex = null, string source = null, params string[] tags)
        {
            var logger = string.IsNullOrWhiteSpace(source) || name.Equals(source) ? nlog : NLog.LogManager.GetLogger(source);

            if (!tags.IsNullOrLength0())
            {
                msg += " 标签:" + JsonUtil.SerializeIgnoreNull(tags);
            }

            var levelEnum = LogLevelHelper.Parse(level);

            switch (levelEnum)
            {
            case LogLevelEnum.TRACE:
                logger.Trace(ex, msg);

                break;

            case LogLevelEnum.DEBUG:
                logger.Debug(ex, msg);

                break;

            case LogLevelEnum.INFO:
                logger.Info(ex, msg);

                break;

            case LogLevelEnum.WRAN:
                logger.Warn(ex, msg);

                break;

            case LogLevelEnum.ERROR:
                logger.Error(ex, msg);

                break;

            case LogLevelEnum.FATAL:
                logger.Fatal(ex, msg);

                break;
            }
        }
Exemplo n.º 3
0
 private void UpdateLoggingLevel()
 {
     LogLevelHelper.SetMinimumLogLevel(LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
 }
        /// <summary>
        /// 将消息与异常写入到存储设备里
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="msg">消息</param>
        /// <param name="eventId">事件ID</param>
        /// <param name="ex">异常</param>
        /// <param name="source">来源</param>
        /// <param name="tags">标签</param>
        protected override void WriteStorage(string level, string msg, string eventId, Exception ex = null, string source = null, params string[] tags)
        {
            if (string.IsNullOrWhiteSpace(source) && ex != null)
            {
                source = ex.Source;
            }
            var      logLevel = LogLevelHelper.Parse(level);
            LogLevel exLevel  = null;

            switch (logLevel)
            {
            case LogLevelEnum.TRACE:
                exLevel = LogLevel.Trace;

                break;

            case LogLevelEnum.DEBUG:
                exLevel = LogLevel.Debug;

                break;

            case LogLevelEnum.INFO:
                exLevel = LogLevel.Info;

                break;

            case LogLevelEnum.WRAN:
                exLevel = LogLevel.Warn;

                break;

            case LogLevelEnum.ERROR:
                exLevel = LogLevel.Error;

                break;

            case LogLevelEnum.FATAL:
                exLevel = LogLevel.Fatal;

                break;

            default:

                return;
            }

            EventBuilder builder = null;

            if (ex == null)
            {
                builder = ExceptionlessClient.Default.CreateLog(source, msg, exLevel);
            }
            else
            {
                builder = ExceptionlessClient.Default.CreateException(ex);
                if (!string.IsNullOrWhiteSpace(source))
                {
                    builder.SetSource(source);
                }
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    builder.SetMessage(msg);
                }
            }
            builder.AddTags(AppendLocalIdTags(eventId, tags));
            builder.Submit();
        }
Exemplo n.º 5
0
 /// <summary>
 /// 日志等级是否开启
 /// </summary>
 /// <param name="logLevel">日志等级</param>
 /// <returns>日志等级是否开启</returns>
 public bool IsEnabled(LogLevel logLevel)
 {
     return(LogLevelHelper.IsNeedWriteLog(logLevel.ToString(), LogRecordLevel.GetRecordLevel()));
 }