private static Exception FormatMessage(StringBuilder bldr, ExceptionReportingData data) { if (!string.IsNullOrEmpty(data.Message)) { bldr.Append("Message (not an exception): "); bldr.AppendLine(data.Message); bldr.AppendLine(); } if (!string.IsNullOrEmpty(data.MessageBeforeStack)) { bldr.AppendLine(data.MessageBeforeStack); } if (data.Error != null) { Exception innerMostException = null; bldr.Append(ErrorReport.GetHiearchicalExceptionInfo(data.Error, ref innerMostException)); //if the exception had inner exceptions, show the inner-most exception first, since that is usually the one //we want the developer to read. if (innerMostException != null) { var oldText = bldr.ToString(); bldr.Clear(); bldr.AppendLine("Inner-most exception:"); bldr.AppendLine(ErrorReport.GetExceptionText(innerMostException)); bldr.AppendLine(); bldr.AppendLine("Full, hierarchical exception contents:"); bldr.Append(oldText); } AddErrorReportingPropertiesToDetails(bldr); return(innerMostException); } if (data.StackTrace != null) { bldr.AppendLine("--Stack--"); bldr.AppendLine(data.StackTrace.ToString()); } return(null); }
protected override bool DisplayError(Exception exception) { if (exception == null) { return(true); } List <string> errors = new List <string>(); errors.Add(ErrorReport.GetExceptionText(exception)); errors.Add("Standard ErrorReport properties for above exception:"); var errorProperties = new SortedDictionary <string, string>(ErrorReport.GetStandardProperties()); errors.AddRange(errorProperties.Select(property => String.Format("{0}: {1}", property.Key, property.Value))); /* Commented out: Adding platform properties is unnecessary since ErrorReport's OSVersion property will tell us more anyway * errors.Add("Platform properties for above exception:"); * foreach (PropertyInfo property in typeof(Platform).GetProperties()) * { * errors.Add(String.Format("{0}: {1}", property.Name, property.GetValue(typeof(Platform), null))); * } */ _logger.LogMany(SyslogPriority.Error, errors); return(true); }
public void Report(string message, string messageBeforeStack, Exception error, Form owningForm) { try { if (!string.IsNullOrEmpty(message)) { UsageReporter.ReportExceptionString(message); } else if (error != null) { UsageReporter.ReportException(error); } } catch { //swallow } PrepareDialog(); if (!string.IsNullOrEmpty(message)) { _notificationText.Text = message; } if (!string.IsNullOrEmpty(message)) { _details.Text += "Message (not an exception): " + message + Environment.NewLine; _details.Text += Environment.NewLine; } if (!string.IsNullOrEmpty(messageBeforeStack)) { _details.Text += messageBeforeStack; _details.Text += Environment.NewLine; } Exception innerMostException = null; _details.Text += ErrorReport.GetHiearchicalExceptionInfo(error, ref innerMostException); //if the exception had inner exceptions, show the inner-most exception first, since that is usually the one //we want the developer to read. if (innerMostException != null) { _details.Text = string.Format("Inner-most exception:{2}{0}{2}{2}Full, hierarchical exception contents:{2}{1}", ErrorReport.GetExceptionText(innerMostException), _details.Text, Environment.NewLine); } AddErrorReportingPropertiesToDetails(); Debug.WriteLine(_details.Text); if (innerMostException != null) { error = innerMostException; } try { Logger.WriteEvent("Got exception " + error.GetType().Name); } catch (Exception err) { //We have more than one report of dieing while logging an exception. _details.Text += "****Could not write to log (" + err.Message + ")" + Environment.NewLine; _details.Text += "Was trying to log the exception: " + error.Message + Environment.NewLine; _details.Text += "Recent events:" + Environment.NewLine; _details.Text += Logger.MinorEventsLog; } ShowReportDialogIfAppropriate(owningForm); }