/// <summary>
 /// 添加标签
 /// </summary>
 /// <param name="builder">事件生成器</param>
 /// <param name="content">日志内容</param>
 private void AddTags(EventBuilder builder, ILogContent content)
 {
     builder.AddTags(content.Level, content.LogName, content.TraceId);
     if (content.Tags.Any())
     {
         builder.AddTags(content.Tags.ToArray());
     }
 }
예제 #2
0
        public override bool HandleError(Exception ex, EventContext ctx)
        {
            string message = ErrorMessage ?? String.Format("Error processing action: {0}", GetType().Name);

            Log.Error().Project(ctx.Event.ProjectId).Message(message).Exception(ex).Write();

            if (!ctx.Event.Tags.Contains("Internal"))
            {
                EventBuilder b = ex.ToExceptionless()
                                 .AddObject(ctx.Event)
                                 .AddTags("Internal")
                                 .SetUserDescription("*****@*****.**", message);

                b.AddTags(ErrorTags);

                if (IsCritical)
                {
                    b.MarkAsCritical();
                }

                b.Submit();
            }

            return(ContinueOnError);
        }
예제 #3
0
        private static void Submit(EventBuilder builder, string[] tags, List <KeyValuePair <string, object> > propertys)
        {
            if (tags != null)
            {
                builder.AddTags(tags);
            }

            if (propertys != null)
            {
                foreach (var property in propertys)
                {
                    builder.SetProperty(property.Key, property.Value);
                }
            }
            builder.Submit();
        }
        /// <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();
        }
예제 #5
0
 /// <summary>
 /// 添加标签
 /// </summary>
 /// <param name="builder">事件生成器</param>
 /// <param name="content">日志内容</param>
 private void AddTags(EventBuilder builder, ILogContent content) => builder.AddTags(content.Level, content.LogName, content.TraceId);