Пример #1
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var message = formatter(state, exception);
            var source  = $"{_categoryName}";

            EventBuilder eventBuilder = null;

            if (exception != null)
            {
                eventBuilder = ExceptionlessClient.Default.CreateException(exception);
            }
            else
            {
                eventBuilder = ExceptionlessClient.Default.CreateLog(source, message, logLevel.ToString());
            }

            eventBuilder.SetMessage(message).SetSource(source);

            if (eventId != 0)
            {
                eventBuilder.SetProperty("enentId", eventId);
            }

            eventBuilder.Submit();
        }
Пример #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();
        }
Пример #4
0
        /// <summary>
        /// 提交消息
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="level">日志等级</param>
        /// <param name="user">用户信息</param>
        /// <param name="datas">自定义数据</param>
        /// <param name="tags">标签</param>
        protected static void Submit(string message, LogLevel level, ExcUserParam user, List <ExcDataParam> datas, params string[] tags)
        {
            EventBuilder builder = ExceptionlessManager.Instance.ToMessageLess(message, level)
                                   .AddTags(tags)
                                   .SetUserIdentity(user?.Id, user?.Name)
                                   .SetUserDescription(user?.Email, user?.Description)
                                   .SetReferenceId(Guid.NewGuid().ToString("N"));

            if (datas?.Count > 0)
            {
                foreach (var data in datas)
                {
                    builder.AddObject(data?.Data, data?.Name);
                }
            }
            builder.Submit();
        }
Пример #5
0
        /// <summary>
        /// 提交失效链接
        /// </summary>
        /// <param name="resource">链接地址</param>
        /// <param name="user">用户信息</param>
        /// <param name="datas">自定义数据</param>
        /// <param name="tags">标签</param>
        public void Submit(string resource, ExcUserParam user, List <ExcDataParam> datas, params string[] tags)
        {
            EventBuilder builder = ExceptionlessClient.Default.CreateNotFound(resource)
                                   .AddTags(tags)
                                   .SetUserIdentity(user?.Id, user?.Name)
                                   .SetUserDescription(user?.Email, user?.Description)
                                   .SetReferenceId(Guid.NewGuid().ToString("N"));

            if (datas?.Count > 0)
            {
                foreach (var data in datas)
                {
                    builder.AddObject(data?.Data, data?.Name);
                }
            }
            builder.Submit();
        }
Пример #6
0
        /// <summary>
        /// 提交异常
        /// </summary>
        /// <param name="ex">异常信息</param>
        /// <param name="user">用户信息</param>
        /// <param name="datas">自定义数据</param>
        /// <param name="tags">标签</param>
        public static void Submit(this Exception ex, ExcUserParam user, List <ExcDataParam> datas, params string[] tags)
        {
            EventBuilder builder = ex.ToExceptionless()
                                   .AddTags(tags)
                                   .SetUserIdentity(user?.Id, user?.Name)
                                   .SetUserDescription(user?.Email, user?.Description)
                                   .SetReferenceId(Guid.NewGuid().ToString("N"));

            if (datas?.Count > 0)
            {
                foreach (var data in datas)
                {
                    builder.AddObject(data?.Data, data?.Name);
                }
            }
            builder.Submit();
        }
        public static LogBuilder Report(this LogBuilder builder, Action <EventBuilder> errorBuilderAction = null)
        {
            if (builder.LogEventInfo.Exception != null)
            {
                EventBuilder exBuilder = builder.LogEventInfo.Exception.ToExceptionless();

                if (errorBuilderAction != null)
                {
                    errorBuilderAction(exBuilder);
                }

                exBuilder.AddObject(builder.LogEventInfo, name: "Log Info", excludedPropertyNames: new List <string> {
                    "Exception", "Message", "LoggerShortName", "SequenceID", "TimeStamp"
                });

                exBuilder.Submit();
            }

            return(builder);
        }
        /// <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();
        }
Пример #9
0
 public void EventLog(EventBuilder builder)
 {
     builder.Client = client;
     builder.Submit();
 }