protected AMemberItem(AMemberItem parent, string name, XElement element) : base(parent, name, element) { Remarks = RemarksItem.GetFrom(this); Example = ExampleItem.GetFrom(this); Exceptions = ExceptionItem.GetFrom(this); }
protected void Application_Error(Object sender, EventArgs e) { string boolString = ConfigurationSettings.AppSettings["ExceptionLogging"]; //Logg error only if logging enabled if (bool.Parse(boolString)) { ExceptionItem ex = new ExceptionItem(); HttpContext ctx = HttpContext.Current; string referrer, sForm, qryStr; referrer = sForm = qryStr = string.Empty; if (ctx.Request.ServerVariables["HTTP_REFERER"] != null) { referrer = ctx.Request.ServerVariables["HTTP_REFERER"].ToString(); } ex.Referrer = referrer; sForm = (ctx.Request.Form != null) ? ctx.Request.Form.ToString() : string.Empty; ex.FormVars = sForm; qryStr = (ctx.Request.QueryString != null) ? ctx.Request.QueryString.ToString() : string.Empty; ex.QueryString = qryStr; ex.ExceptionDetails = Server.GetLastError().GetBaseException(); ExceptionInsertHelper.Execute(ex); } }
private void checkNewItem(Exceptable <T1> items, ExceptionItem <T1> item, string name, List <int> sortOrders, List <Guid> roleIDs, MessageDisplay msgDisplay) { if (item != null) { if (item.SortOrder == -1) { int maxSortOrder = 0; foreach (int sortOrder in sortOrders) { if (sortOrder > maxSortOrder) { maxSortOrder = sortOrder; } } item.SortOrder = maxSortOrder + 1; } else if (sortOrders.Contains(item.SortOrder) && msgDisplay.HasAnyError() == false) { msgDisplay.AddError("new_" + name, "排序数字不能重复"); } if (item.RoleID != Guid.Empty && roleIDs.Contains(item.RoleID)) { msgDisplay.AddError("new_" + name, "已经存在对用户组“" + AllSettings.Current.RoleSettings.GetRole(item.RoleID).Name + "”的例外设置,不能重复设置"); } else { if (item.RoleID != Guid.Empty) { roleIDs.Add(item.RoleID); } } items.Add(item); } }
private void checkItem(Exceptable <T1> items, ExceptionItem <T1> item, string name, int id, List <int> sortOrders, List <Guid> roleIDs, MessageDisplay msgDisplay) { if (item != null) { //msgDisplay.HasAnyError == false 是为避免 有两个SortOrder 不为数字出错了(这时都为0) 而这里又提示重复 if (id != 0 && sortOrders.Contains(item.SortOrder) && msgDisplay.HasAnyError() == false) { msgDisplay.AddError(name, id, "排序数字不能重复"); } else { if (id != 0) { sortOrders.Add(item.SortOrder); } //items.Add(item); } if (item.RoleID != Guid.Empty && roleIDs.Contains(item.RoleID)) { msgDisplay.AddError(name, id, "已经存在对用户组“" + AllSettings.Current.RoleSettings.GetRole(item.RoleID).Name + "”的例外设置,不能重复设置"); } else { if (item.RoleID != Guid.Empty) { roleIDs.Add(item.RoleID); } items.Add(item); } } }
private static string GetExceptionDetailTag(Exception ex, ExceptionItem item, int tabLevel) { string tag = string.Empty; tag += "<b>" + item + "</b><br/>"; tag += GetExceptionItem(ex, item, ExceptionTextFormat.HTML, tabLevel) + "<br/>"; return(tag); }
private static string GetExceptionItem(Exception ex, ExceptionItem item, ExceptionTextFormat format, int tabLevel) { string itemText = string.Empty; switch (item) { case ExceptionItem.Message: itemText = ex.Message; break; case ExceptionItem.StackTrace: if (!string.IsNullOrEmpty(ex.StackTrace)) { itemText = ex.StackTrace; //move the source line to the top const string inTag = " in "; if (itemText.Contains(inTag)) { itemText = itemText.Substring(itemText.LastIndexOf(inTag) + 4) + "\r\n" + itemText.Substring(0, itemText.LastIndexOf(inTag)); } if (format == ExceptionTextFormat.HTML) { itemText = itemText.Replace(" at ", "<br>at "); } } break; case ExceptionItem.Target: if (ex.TargetSite != null && !string.IsNullOrEmpty(ex.TargetSite.Name)) { itemText = ex.TargetSite.Name; } break; case ExceptionItem.Type: itemText = ex.GetType().ToString(); break; } itemText = string.IsNullOrEmpty(itemText) ? "N/A" : itemText; if (format == ExceptionTextFormat.HTML) { itemText = "<ul><li>" + itemText; itemText.Replace("\r\n", "<br>"); int len = itemText.Split(new[] { "<ul>" }, StringSplitOptions.None).Length - 1; for (int i = 0; i < len; i++) { itemText += "</li></ul>"; } } else { itemText = "\t" + itemText.Trim(); itemText = itemText.Replace("\r\n", "\r\n\t\t ".PadRight(tabLevel, '\t')); } return(itemText); }
private async Task HandleErrorManagement(string identifier, ExceptionItem exceptionItem, Exception ex) { exceptionItem.Source = ex.Source; exceptionItem.ErrorMethod = identifier; exceptionItem.Message = ex.Message; if (ex.InnerException != null) { await HandleErrorManagement("inner_" + identifier, exceptionItem, ex.InnerException); } }
private void AnalyzeStoryTaskWithException() { foreach (var story in CurrentSprint.GetUnCompletedStories()) { var errorDesc = string.Empty; var errorType = string.Empty; var errorImg = string.Empty; decimal diffDesc = 0; if (IsSizeMismatch(story, ref errorType, ref errorDesc, ref errorImg, ref diffDesc)) { var exItem = new ExceptionItem() { Owner = NameUtil.ConvertToEngName(story.Owner), Item = story.Type + " " + story.ID + " " + story.Title, ExceptionCategory = errorType, ExceptionImg = errorImg, ExceptionDetail = errorDesc, Diff = diffDesc }; StoriesInException.Add(exItem); } foreach (var task in story.GetInCompleteTasks()) { if (NameUtil.ConvertToEngName(task.Owner) == NameUtil.NoOwner) { var exItem = new ExceptionItem() { Owner = NameUtil.ConvertToEngName(task.Owner), Item = "Task " + task.ID + " " + task.Description, ExceptionCategory = "No Owner", ExceptionImg = "No Owner", ExceptionDetail = "This task has no owner. It belongs to " + story.Type + " " + story.GetBreifDesc() }; TasksInException.Add(exItem); } else if (task.Estimate == 0) { var exItem = new ExceptionItem() { Owner = NameUtil.ConvertToEngName(task.Owner), Item = "Task " + task.ID + " " + task.Description, ExceptionCategory = "This task's estimation is 0", ExceptionImg = "Zero", ExceptionDetail = "This task's estimation is 0. It belongs to " + story.Type + " " + story.GetBreifDesc() }; TasksInException.Add(exItem); } } //Michael Task or Story size is 0/ } }
public async Task PublishError(string identifier, ExceptionItem exceptionItem) { try { await Task.Run(() => { _logger.Error(string.Format(Constant.LoggingFormat, identifier, exceptionItem.Message), JsonConvert.SerializeObject(exceptionItem)); }); } catch (Exception) { } }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is ExceptionData exceptionData)) { return(false); } if (null == exceptionData.Exceptions || 0 == exceptionData.Exceptions.Count) { return(false); } foreach (var exceptionDetails in exceptionData.Exceptions) { ExceptionItem exceptionItem = new ExceptionItem(); if (exceptionData.Properties.TryGetValue("RequestId", out string requestId)) { exceptionItem.RequestId = requestId; } if (exceptionData.Properties.TryGetValue("CategoryName", out string categoryName)) { exceptionItem.Category = categoryName; } if (exceptionData.Properties.TryGetValue("RequestPath", out string path)) { exceptionItem.Path = path; } if (exceptionData.Properties.TryGetValue("ConnectionId", out string connectionId)) { exceptionItem.ConnectionId = connectionId; } if (exceptionData.Properties.TryGetValue("FormattedMessage", out string message)) { exceptionItem.Message = message; } if (exceptionData.Properties.TryGetValue("EventName", out string eventName)) { exceptionItem.Name = eventName; } exceptionItem.ExceptionId = exceptionDetails.Id; exceptionItem.ExceptionMessage = exceptionDetails.Message; exceptionItem.ExceptionType = exceptionDetails.TypeName; if (null != exceptionDetails.ParsedStack && 0 < exceptionDetails.ParsedStack.Count) { exceptionItem.StackTrace = string.Join(Environment.NewLine, exceptionDetails.ParsedStack.Select(s => s.ToString())); } analyticsItem.Exceptions.Add(exceptionItem); } return(true); }
private ExceptionItem <string> GetItem <T>() { ExceptionItem <T> item = (ExceptionItem <T>)Parameters["Item"]; ExceptionItem <string> tempItem = new ExceptionItem <string>(); tempItem.LevelStatus = item.LevelStatus; tempItem.RoleID = item.RoleID; tempItem.SortOrder = item.SortOrder; tempItem.Value = item.Value.ToString(); return(tempItem); }
public ExceptionItem HandleError(string identifier, Exception ex) { var exceptionItem = new ExceptionItem(); try { HandleErrorManagement(identifier, exceptionItem, ex); // TODO : LOG PROVIDER TO FILE WRITE THE LOG } catch (Exception) { } return(exceptionItem); }
public async Task <ExceptionItem> HandleError(string identifier, Exception ex) { var exceptionItem = new ExceptionItem(); try { await HandleErrorManagement(identifier, exceptionItem, ex); await _logProvider.PublishError("RegisterSearchText", exceptionItem); } catch (Exception) { } return(exceptionItem); }
public static void Execute(ExceptionItem exDto) { SqlDatabase db = new SqlDatabase(Config.ConnString); DbCommand dbCommand; string sqlCommand = "dbo.spInsertException"; dbCommand = db.GetStoredProcCommand(sqlCommand); db.AddInParameter(dbCommand, "Source", DbType.String, exDto.ExceptionDetails.Source); db.AddInParameter(dbCommand, "LogDateTime", DbType.DateTime, DateTime.Now.ToString()); db.AddInParameter(dbCommand, "Message", DbType.String, exDto.ExceptionDetails.Message); db.AddInParameter(dbCommand, "Form", DbType.String, exDto.FormVars); db.AddInParameter(dbCommand, "QueryString", DbType.String, exDto.QueryString); db.AddInParameter(dbCommand, "TargetSite", DbType.String, exDto.ExceptionDetails.TargetSite.ToString()); db.AddInParameter(dbCommand, "StackTrace", DbType.String, exDto.ExceptionDetails.StackTrace.ToString()); db.AddInParameter(dbCommand, "Referrer", DbType.String, exDto.Referrer); db.ExecuteNonQuery(dbCommand); }
public BlApiException(ExceptionItem item) : base(item.Message) { ApiSource = item.Exception; }
private static string GetExceptionItem(Exception ex, ExceptionItem item, ExceptionTextFormat format, int tabLevel) { string itemText = string.Empty; switch (item) { case ExceptionItem.Message: itemText = ex.Message; break; case ExceptionItem.StackTrace: if (!string.IsNullOrEmpty(ex.StackTrace)) { itemText = ex.StackTrace; //move the source line to the top const string inTag = " in "; if (itemText.Contains(inTag)) { itemText = itemText.Substring(itemText.LastIndexOf(inTag) + 4) + "\r\n" + itemText.Substring(0, itemText.LastIndexOf(inTag)); } if (format == ExceptionTextFormat.HTML) itemText = itemText.Replace(" at ", "<br>at "); } break; case ExceptionItem.Target: if (ex.TargetSite != null && !string.IsNullOrEmpty(ex.TargetSite.Name)) itemText = ex.TargetSite.Name; break; case ExceptionItem.Type: itemText = ex.GetType().ToString(); break; } itemText = string.IsNullOrEmpty(itemText) ? "N/A" : itemText; if (format == ExceptionTextFormat.HTML) { itemText = "<ul><li>" + itemText; itemText.Replace("\r\n", "<br>"); int len = itemText.Split(new[] {"<ul>"}, StringSplitOptions.None).Length - 1; for (int i = 0; i < len; i++) itemText += "</li></ul>"; } else { itemText = "\t" + itemText.Trim(); itemText = itemText.Replace("\r\n", "\r\n\t\t ".PadRight(tabLevel, '\t')); } return itemText; }
private static string GetExceptionDetailTag(Exception ex, ExceptionItem item, int tabLevel) { string tag = string.Empty; tag += "<b>" + item + "</b><br/>"; tag += GetExceptionItem(ex, item, ExceptionTextFormat.HTML, tabLevel) + "<br/>"; return tag; }
/// <summary> /// 获取 除了例外的 用户组 排序 级别 还未获取T的值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="id"></param> /// <param name="isNew"></param> /// <param name="msgDisplay"></param> /// <returns></returns> private ExceptionItem <T1> GetExceptionItem(string name, int id, bool isNew, MessageDisplay msgDisplay) { if (_Request.Get <int>("delete_" + name + "_" + id, Method.Post, 0) == 1)//被删除的项 { return(null); } Guid roleID; LevelStatus level = LevelStatus.Currently; int sortOrder = 0; if (id == 0 && isNew == false) { roleID = Guid.Empty; } else { string roleIDName, sortOrderName, levelName; if (isNew) { roleIDName = "new_" + name + "_role"; sortOrderName = "new_" + name + "_sortorder"; levelName = "new_" + name + "_level"; } else { roleIDName = name + "_role_" + id; sortOrderName = name + "_sortorder_" + id; levelName = name + "_level_" + id; } roleID = _Request.Get <Guid>(roleIDName, Method.Post, Guid.Empty); if (roleID == Guid.Empty) { if (isNew && _Request.Get("display_tr_" + name, Method.Post, "0") == "1") { msgDisplay.AddError("new_" + name, "请选择一个用户组"); } else { return(null); } } string value = _Request.Get(sortOrderName, Method.Post, string.Empty); if (value == string.Empty) { sortOrder = -1; } else if (!int.TryParse(value, out sortOrder)) { if (isNew) { msgDisplay.AddError("new_" + name, "排序必须为整数"); } else { msgDisplay.AddError(name, id, "排序必须为整数"); } } level = _Request.Get <LevelStatus>(levelName, Method.Post, LevelStatus.Currently); } bool hasError; ExceptionItem <T1> t = new ExceptionItem <T1>(); t.LevelStatus = level; t.RoleID = roleID; t.SortOrder = sortOrder; t.Value = GetItemValue(name, id, isNew, msgDisplay, out hasError); if (hasError) { return(null); } return(t); }