/// <summary> /// Cleanup when WorkerRole is stopped /// </summary> public override void OnStop() { try { Log.Info(new CallerInfo(), LogContext.FrontEnd, "WorkerRole is stopping"); this.cancellationTokenSource.Cancel(); this.runCompleteEvent.WaitOne(); base.OnStop(); Log.Info(new CallerInfo(), LogContext.FrontEnd, "WorkerRole has stopped"); } catch (Exception e) { Log.Error(new CallerInfo(), LogContext.FrontEnd, "Exception on shutdown: {0}", e.ToString()); throw; } finally { AppDomain.CurrentDomain.UnhandledException -= this.OnAppDomainUnhandledException; TaskScheduler.UnobservedTaskException -= this.OnUnobservedTaskException; Log.Flush(); } }
/// <summary> /// Log any unhandled exceptions that are raised in the service /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { Log.Error(new CallerInfo(), FrontEnd.Logging.LogContext.FrontEnd, "Unhandled exception: " + e.ExceptionObject.ToString()); Log.Flush(); // process may or may not be terminating so flush log just in case. }