From bb1e5d854da1fc8dad241bd092ea5f6e4c3d0534 Mon Sep 17 00:00:00 2001 From: Omar Boukli-Hacene Date: Thu, 8 Feb 2024 22:10:17 +0200 Subject: [PATCH] refactor: Handle possible exception --- src/Aktabook.Bus/Program.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Aktabook.Bus/Program.cs b/src/Aktabook.Bus/Program.cs index 70a8be9..dd45781 100644 --- a/src/Aktabook.Bus/Program.cs +++ b/src/Aktabook.Bus/Program.cs @@ -128,12 +128,17 @@ { Log.Fatal(criticalErrorContext.Exception, "Critical error: {Error}", criticalErrorContext.Error); - await criticalErrorContext.Stop(cancellationToken).ConfigureAwait(false); - - await Log.CloseAndFlushAsync().ConfigureAwait(false); - - string output = $"NServiceBus critical error:\n{criticalErrorContext.Error}\nShutting down."; - Environment.FailFast(output, criticalErrorContext.Exception); + try + { + await criticalErrorContext.Stop(cancellationToken).ConfigureAwait(false); + } + finally + { + await Log.CloseAndFlushAsync().ConfigureAwait(false); + + string output = $"NServiceBus critical error:\n{criticalErrorContext.Error}\nShutting down."; + Environment.FailFast(output, criticalErrorContext.Exception); + } }); return endpointConfiguration;