public void AddCorrelationAppendsToTheMessage()
        {
            CorrelatedExceptionEventArgs e = new CorrelatedExceptionEventArgs("foo", new Exception(), "reported by", false);
            e.AddCorrelationMessage("bar");

            Assert.AreEqual("foo\nbar", e.Message);
        }
        private static void ReportInternal(string message, Exception unhandledException, bool includeReporterStackTrace)
        {
            if (recursionGuard == 2)
            {
                return; // We've already had one recursion, stop recursing.
            }
            int oldRecursionGuard = recursionGuard;

            try
            {
                recursionGuard += 1;

                CorrelatedExceptionEventArgs e = new CorrelatedExceptionEventArgs(message,
                                                                                  unhandledException,
                                                                                  includeReporterStackTrace ? GetCallersCallerStackTrace() : null,
                                                                                  oldRecursionGuard != 0);

                EventHandlerPolicy.SafeInvoke(correlateUnhandledException, null, e);
                EventHandlerPolicy.SafeInvoke(reportUnhandledException, null, e);
            }
            finally
            {
                recursionGuard = oldRecursionGuard;
            }
        }
        public void PropertiesContainSameValuesAsWereSetInTheConstructor()
        {
            Exception ex = new Exception();
            CorrelatedExceptionEventArgs e = new CorrelatedExceptionEventArgs("foo", ex, "reported by", true);

            Assert.AreEqual("foo", e.Message);
            Assert.AreEqual("reported by", e.ReporterStackTrace);
            Assert.AreSame(ex, e.Exception);
            Assert.IsTrue(e.IsRecursive);
        }
 private static void LogImpl(CorrelatedExceptionEventArgs e)
 {
     try
     {
         using (var sw = new StreamWriter(Paths.BlackBoxLogFile, true))
         {
             sw.WriteLine(string.Format("Unhandled exception reported at: {0}", DateTime.Now));
             sw.WriteLine(e.Message);
             sw.WriteLine();
             sw.WriteLine(e.GetDescription());
             sw.WriteLine();
         }
     }
     catch
     { 
         // eat any exceptions
     }
 }
        private static void ReportUnhandledException(object sender, CorrelatedExceptionEventArgs e)
        {
            Form currentOwner;
            lock (syncRoot)
            {
                if (installedOwner == null || installedOwner.IsDisposed)
                {
                    Uninstall();
                    return;
                }

                currentOwner = installedOwner;
            }

            Sync.Invoke(currentOwner, () => ErrorDialog.Show(currentOwner, "Unhandled Exception", e.Message, e.GetDetails()));
        }
        private static void HandleUnhandledExceptionNotification(object sender, CorrelatedExceptionEventArgs e)
        {
            if (e.IsRecursive)
                return;

            RuntimeAccessor.Logger.Log(LogSeverity.Error, "Internal error: " + e.GetDescription());
        }
 public static void Log(CorrelatedExceptionEventArgs e)
 {
     Logger.Write(bl => LogImpl(e));
 }
 public void AddCorrelationThrowsWhenMessageIsNull()
 {
     CorrelatedExceptionEventArgs e = new CorrelatedExceptionEventArgs("foo", new Exception(), "reported by", true);
     e.AddCorrelationMessage(null);
 }
        private static void ReportInternal(string message, Exception unhandledException, bool includeReporterStackTrace)
        {
            if (recursionGuard == 2)
                return; // We've already had one recursion, stop recursing.

            int oldRecursionGuard = recursionGuard;
            try
            {
                recursionGuard += 1;

                CorrelatedExceptionEventArgs e = new CorrelatedExceptionEventArgs(message,
                    unhandledException,
                    includeReporterStackTrace ? GetCallersCallerStackTrace() : null,
                    oldRecursionGuard != 0);

                EventHandlerPolicy.SafeInvoke(correlateUnhandledException, null, e);
                EventHandlerPolicy.SafeInvoke(reportUnhandledException, null, e);
            }
            finally
            {
                recursionGuard = oldRecursionGuard;
            }
        }
 private void OnUnhandledException(object sender, CorrelatedExceptionEventArgs e)
 {
     tappedLogger.RecordLogMessage(LogSeverity.Error, e.GetDescription(), null);
 }
 private static void CorrelateUnhandledException(object sender, CorrelatedExceptionEventArgs e)
 {
     ITestContext context = TestContextTrackerAccessor.Instance.CurrentContext;
     if (context != null)
         e.AddCorrelationMessage(String.Format("The exception occurred while test step '{0}' was running.", context.TestStep.FullName));
 }