Exemple #1
0
        /// <summary>
        /// Creates the error message, logs it to file and displays it in
        /// an <see cref="ExceptionDialog"/>.
        /// </summary>
        /// <param name="e">The <see cref="Exception"/> to show.</param>
        public static void HandleException(Exception e)
        {
            // Add error to error log
            var exceptionLogFile = Path.Combine(Properties.Settings.Default.LogfilePath, "exception.log");

            var message        = new StringBuilder(e.Message);
            var innerException = e;

            message.AppendLine("------------------------------------");

            var trace = new StackTrace(e, true);

            message.AppendLine("Method name:" + trace.GetFrame(0).GetMethod().Name);
            message.AppendLine("Line: " + trace.GetFrame(0).GetFileLineNumber());
            message.AppendLine("Column: " + trace.GetFrame(0).GetFileColumnNumber());

            // Loop inner exceptions.
            while (innerException.InnerException != null)
            {
                innerException = innerException.InnerException;
                message.AppendLine(GetLogEntryForException(innerException));
            }

            message.AppendLine(GetLogEntryForException(innerException));

            using (var w = File.AppendText(exceptionLogFile))
            {
                Log(message.ToString(), w);

                // Close the writer and underlying file.
                w.Close();
            }

            var newExceptionDlg = new ExceptionDialog
            {
                ExceptionMessage = e.Message,
                ExceptionDetails = message.ToString()
            };

            var result = newExceptionDlg.ShowDialog();

            switch (result)
            {
            case DialogResult.Abort:
                Application.Exit();
                break;

            case DialogResult.OK:
                break;
            }
        }
Exemple #2
0
    /// <summary>
    /// Creates the error message, logs it to file and displays it in 
    /// an <see cref="ExceptionDialog"/>.
    /// </summary>
    /// <param name="e">The <see cref="Exception"/> to show.</param>
    public static void HandleException(Exception e)
    {
      // Add error to error log
      var exceptionLogFile = Path.Combine(Properties.Settings.Default.LogfilePath, "exception.log");

      var message = new StringBuilder(e.Message);
      var innerException = e;
      message.AppendLine("------------------------------------");

      var trace = new StackTrace(e, true);
      message.AppendLine("Method name:" + trace.GetFrame(0).GetMethod().Name);
      message.AppendLine("Line: " + trace.GetFrame(0).GetFileLineNumber());
      message.AppendLine("Column: " + trace.GetFrame(0).GetFileColumnNumber());

      // Loop inner exceptions.
      while (innerException.InnerException != null)
      {
        innerException = innerException.InnerException;
        message.AppendLine(GetLogEntryForException(innerException));
      }

      message.AppendLine(GetLogEntryForException(innerException));

      using (var w = File.AppendText(exceptionLogFile))
      {
        Log(message.ToString(), w);

        // Close the writer and underlying file.
        w.Close();
      }

      var newExceptionDlg = new ExceptionDialog
        {
          ExceptionMessage = e.Message,
          ExceptionDetails = message.ToString()
        };

      var result = newExceptionDlg.ShowDialog();
      switch (result)
      {
        case DialogResult.Abort:
          Application.Exit();
          break;
        case DialogResult.OK:
          break;
      }
    }