コード例 #1
0
 private async Task SendErrorExceptionAsync(Exception exception, string format = null, params object[] args)
 {
     try {
         var report = ErrorReportGenerator.CreateReport(CurrentContext.AwsRequestId, LambdaLogLevel.ERROR.ToString(), exception, format, args);
         await PublishErrorReportAsync(null, report);
     } catch {
         // log the error; it's the best we can do
         LogError(exception, format, args);
     }
 }
コード例 #2
0
        /// <summary>
        /// Handles the unhandled exception.
        /// </summary>
        /// <param name="e">The <see cref="System.UnhandledExceptionEventArgs"/> instance containing the event data.</param>
        /// <remarks>Documented by Dev05, 2009-06-25</remarks>
        private static void HandleUnhandledException(UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = e.ExceptionObject as Exception;

                Trace.WriteLine("Unhandled Exception: " + ex.ToString());

                try
                {
                    string errorMsg = "An application error occurred. Please contact the administrator with the following information:"
                                      + Environment.NewLine + Environment.NewLine;

                    // Since we can't prevent the app from terminating, log this to the event log.
                    if (!EventLog.SourceExists("MemoryLifter"))
                    {
                        EventLog.CreateEventSource("MemoryLifter", "Application");
                    }

                    // Create an EventLog instance and assign its source.
                    EventLog myLog = new EventLog();
                    myLog.Source = "MemoryLifter";
                    myLog.WriteEntry(errorMsg + ex.Message + Environment.NewLine + Environment.NewLine + "Stack Trace:" + Environment.NewLine + ex.StackTrace);
                }
                catch (System.Security.SecurityException)
                {
                    Trace.WriteLine("Could not write exception to the Windows EventLog for security reasons.");
                }

                ErrorReportGenerator.ReportError(e.ExceptionObject as Exception, true);
            }
            catch (Exception exp)
            {
                try
                {
                    MessageBox.Show("Could not create an error report. Reason: " + Environment.NewLine + exp.ToString(),
                                    "Error Report Creation Failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    Environment.Exit(-1);
                }
            }
        }