コード例 #1
0
        /// <summary>
        /// 默认初始化
        /// </summary>
        /// <param name="minLogLevel">最小日志等级,如果为null,则从配置里取</param>
        public static void DefaultInit(LogLevel minLogLevel = null)
        {
            if (isExecDefaultInit)
            {
                return;
            }

            ExceptionlessClient.Default.Configuration.ApiKey    = ApiKey;
            ExceptionlessClient.Default.Configuration.ServerUrl = ServerUrl;

            if (minLogLevel == null)
            {
                var logLevel = LogLevelHelper.Parse(RecordLevel);
                switch (logLevel)
                {
                case LogLevelEnum.TRACE:
                    minLogLevel = LogLevel.Trace;

                    break;

                case LogLevelEnum.DEBUG:
                    minLogLevel = LogLevel.Debug;

                    break;

                case LogLevelEnum.INFO:
                    minLogLevel = LogLevel.Info;

                    break;

                case LogLevelEnum.WRAN:
                    minLogLevel = LogLevel.Warn;

                    break;

                case LogLevelEnum.ERROR:
                    minLogLevel = LogLevel.Error;

                    break;

                case LogLevelEnum.FATAL:
                    minLogLevel = LogLevel.Fatal;

                    break;

                default:
                    minLogLevel = LogLevel.Off;

                    break;
                }
            }

            ExceptionlessClient.Default.Configuration.SetDefaultMinLogLevel(minLogLevel);

            lock (syncIsExecDefaultInit)
            {
                isExecDefaultInit = true;
            }
        }
コード例 #2
0
        /// <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 logLevel = LogLevelHelper.Parse(level);
            var exLevel  = LogLevel.Off;

            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;
            }

            if (ex != null)
            {
                msg += $".异常:msg:{ex.Message},ex:{ex.StackTrace}";
            }

            var builder = ExceptionlessClient.Default.CreateLog(source, msg, exLevel);

            builder.AddTags(AppendLocalIdTags(tags));

            builder.Submit();
        }
コード例 #3
0
        /// <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;
            }
        }
コード例 #4
0
        /// <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;
            }
        }
コード例 #5
0
        /// <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();
        }