Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static string GetHiearchicalExceptionInfo(Exception error, ref Exception innerMostException)
        {
            string x = ErrorReport.GetExceptionText(error);

            if (error.InnerException != null)
            {
                innerMostException = error.InnerException;

                x += "**Inner Exception:\r\n";
                x += GetHiearchicalExceptionInfo(error.InnerException, ref innerMostException);
            }
            return(x);
        }
Example #2
0
        //This implementation is a stripped down version of what is found in
        //ExceptionReportingDialog.Report(string message, string messageBeforeStack, Exception error, Form owningForm)
        private void WriteExceptionToConsole(Exception error, string message, Severity severity)
        {
            var textToReport = GetErrorStamp(severity);

            Exception innerMostException = null;

            textToReport += 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)
            {
                textToReport += "Inner-most exception:\r\n" + ErrorReport.GetExceptionText(innerMostException) +
                                "\r\n\r\nFull, hierarchical exception contents:\r\n" + textToReport;
            }

            textToReport += ErrorReportingProperties;

            if (!string.IsNullOrEmpty(message))
            {
                textToReport += "Message (not an exception): " + message + Environment.NewLine;
                textToReport += Environment.NewLine;
            }

            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.
                textToReport += "****Could not write to log (" + err.Message + ")" + Environment.NewLine;
                textToReport += "Was trying to log the exception: " + error.Message + Environment.NewLine;
                textToReport += "Recent events:" + Environment.NewLine;
                textToReport += Logger.MinorEventsLog;
            }
            Console.WriteLine(textToReport);
        }
        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
            }

            if (!string.IsNullOrEmpty(message))
            {
                Console.WriteLine("Message (not an exception): " + message);
                _details += "Message (not an exception): " + message + Environment.NewLine;
                _details += Environment.NewLine;
            }
            if (!string.IsNullOrEmpty(messageBeforeStack))
            {
                Console.WriteLine(messageBeforeStack);
                _details += messageBeforeStack;
                _details += Environment.NewLine;
            }

            Exception innerMostException = null;

            _details += ErrorReport.GetHiearchicalExceptionInfo(error, ref innerMostException);
            Console.WriteLine(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 += "Inner-most exception:\r\n" + ErrorReport.GetExceptionText(innerMostException) +
                            "\r\n\r\nFull, hierarchical exception contents:\r\n" + _details;
                Console.WriteLine("Inner-most exception:\r\n" + ErrorReport.GetExceptionText(innerMostException) +
                                  "\r\n\r\nFull, hierarchical exception contents:\r\n");
            }

            AddErrorReportingPropertiesToDetails();


            Debug.WriteLine(_details);
            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.
                Console.WriteLine("****Could not write to log (" + err.Message + ")");
                _details += "****Could not write to log (" + err.Message + ")" + Environment.NewLine;
                Console.WriteLine("****Could not write to log (" + err.Message + ")");
                _details += "Was trying to log the exception: " + error.Message + Environment.NewLine;
                Console.WriteLine("Recent events:");
                _details += "Recent events:" + Environment.NewLine;
                Console.WriteLine(Logger.MinorEventsLog);
                _details += Logger.MinorEventsLog;
            }

            ShowReportDialogIfAppropriate(owningForm);
        }