From 341696dcd82ccad4ed6606f4ffba6f5e44f1f9a5 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 18 Feb 2025 16:38:00 +0100 Subject: [PATCH 1/3] Log when application is done to determine if process was killed --- src/ServiceControl.Audit/Program.cs | 47 ++++++++++++++---------- src/ServiceControl.Monitoring/Program.cs | 37 ++++++++++++------- src/ServiceControl/Program.cs | 47 ++++++++++++++---------- 3 files changed, 79 insertions(+), 52 deletions(-) diff --git a/src/ServiceControl.Audit/Program.cs b/src/ServiceControl.Audit/Program.cs index 204f572f82..aa4111d3f3 100644 --- a/src/ServiceControl.Audit/Program.cs +++ b/src/ServiceControl.Audit/Program.cs @@ -7,31 +7,40 @@ using ServiceControl.Configuration; using ServiceControl.Infrastructure; -AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception); +try +{ + AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception); -// Hack: See https://github.com/Particular/ServiceControl/issues/4392 -var exitCode = await IntegratedSetup.Run(); + // Hack: See https://github.com/Particular/ServiceControl/issues/4392 + var exitCode = await IntegratedSetup.Run(); -if (exitCode != 0) -{ - return exitCode; -} + if (exitCode != 0) + { + return exitCode; + } -ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly()); + ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly()); -var arguments = new HostArguments(args); + var arguments = new HostArguments(args); -if (arguments.Help) -{ - arguments.PrintUsage(); - return 0; -} + if (arguments.Help) + { + arguments.PrintUsage(); + return 0; + } -var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace); -LoggingConfigurator.ConfigureLogging(loggingSettings); + var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace); + LoggingConfigurator.ConfigureLogging(loggingSettings); -var settings = new Settings(loggingSettings: loggingSettings); + var settings = new Settings(loggingSettings: loggingSettings); -await new CommandRunner(arguments.Command).Execute(arguments, settings); + await new CommandRunner(arguments.Command).Execute(arguments, settings); -return 0; + return 0; +} +finally +{ + // Leave a trail in the logs to determine if the process was killed + NLog.LogManager.GetCurrentClassLogger().Info("Done!"); + NLog.LogManager.Shutdown(); +} \ No newline at end of file diff --git a/src/ServiceControl.Monitoring/Program.cs b/src/ServiceControl.Monitoring/Program.cs index 675eae9a0d..8bd24b3382 100644 --- a/src/ServiceControl.Monitoring/Program.cs +++ b/src/ServiceControl.Monitoring/Program.cs @@ -5,25 +5,34 @@ using ServiceControl.Infrastructure; using ServiceControl.Monitoring; -AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception); +try +{ + AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception); -// Hack: See https://github.com/Particular/ServiceControl/issues/4392 -var exitCode = await IntegratedSetup.Run(); + // Hack: See https://github.com/Particular/ServiceControl/issues/4392 + var exitCode = await IntegratedSetup.Run(); -if (exitCode != 0) -{ - return exitCode; -} + if (exitCode != 0) + { + return exitCode; + } -ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly()); + ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly()); -var arguments = new HostArguments(args); + var arguments = new HostArguments(args); -var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace); -LoggingConfigurator.ConfigureLogging(loggingSettings); + var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace); + LoggingConfigurator.ConfigureLogging(loggingSettings); -var settings = new Settings(loggingSettings: loggingSettings); + var settings = new Settings(loggingSettings: loggingSettings); -await new CommandRunner(arguments.Command).Execute(arguments, settings); + await new CommandRunner(arguments.Command).Execute(arguments, settings); -return 0; + return 0; +} +finally +{ + // Leave a trail in the logs to determine if the process was killed + NLog.LogManager.GetCurrentClassLogger().Info("Done!"); + NLog.LogManager.Shutdown(); +} \ No newline at end of file diff --git a/src/ServiceControl/Program.cs b/src/ServiceControl/Program.cs index aca5bfc780..b71c95a467 100644 --- a/src/ServiceControl/Program.cs +++ b/src/ServiceControl/Program.cs @@ -7,31 +7,40 @@ using ServiceControl.Hosting.Commands; using ServiceControl.Infrastructure; -AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception); +try +{ + AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception); -// Hack: See https://github.com/Particular/ServiceControl/issues/4392 -var exitCode = await IntegratedSetup.Run(); + // Hack: See https://github.com/Particular/ServiceControl/issues/4392 + var exitCode = await IntegratedSetup.Run(); -if (exitCode != 0) -{ - return exitCode; -} + if (exitCode != 0) + { + return exitCode; + } -ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly()); + ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly()); -var arguments = new HostArguments(args); + var arguments = new HostArguments(args); -if (arguments.Help) -{ - arguments.PrintUsage(); - return 0; -} + if (arguments.Help) + { + arguments.PrintUsage(); + return 0; + } -var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace); -LoggingConfigurator.ConfigureLogging(loggingSettings); + var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace); + LoggingConfigurator.ConfigureLogging(loggingSettings); -var settings = new Settings(loggingSettings: loggingSettings); + var settings = new Settings(loggingSettings: loggingSettings); -await new CommandRunner(arguments.Command).Execute(arguments, settings); + await new CommandRunner(arguments.Command).Execute(arguments, settings); -return 0; + return 0; +} +finally +{ + // Leave a trail in the logs to determine if the process was killed + NLog.LogManager.GetCurrentClassLogger().Info("Done!"); + NLog.LogManager.Shutdown(); +} \ No newline at end of file From dd1ca69945c870fa0e0af590e4a47dfe0e61d767 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 18 Feb 2025 16:43:44 +0100 Subject: [PATCH 2/3] Logging when Raven.Embedded.EmbeddedServer started/completed as this operation can take a while and can take longer than the host allows --- src/ServiceControl.RavenDB/EmbeddedDatabase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ServiceControl.RavenDB/EmbeddedDatabase.cs b/src/ServiceControl.RavenDB/EmbeddedDatabase.cs index afadda76ea..d54f1b8467 100644 --- a/src/ServiceControl.RavenDB/EmbeddedDatabase.cs +++ b/src/ServiceControl.RavenDB/EmbeddedDatabase.cs @@ -176,7 +176,9 @@ public void Dispose() EmbeddedServer.Instance.ServerProcessExited -= OnServerProcessExited; shutdownTokenSource.Cancel(); + Logger.Debug("Disposing RavenDB server"); EmbeddedServer.Instance.Dispose(); + Logger.Debug("Dispose RavenDB server"); shutdownTokenSource.Dispose(); applicationStoppingRegistration.Dispose(); From 511fec124d45450fc0fe1e05bcdb3459c4b0f9ab Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Mon, 3 Mar 2025 17:35:39 +0100 Subject: [PATCH 3/3] Improve logging and code comments --- src/ServiceControl.Audit/Program.cs | 4 ++-- src/ServiceControl.Monitoring/Program.cs | 4 ++-- src/ServiceControl/Program.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ServiceControl.Audit/Program.cs b/src/ServiceControl.Audit/Program.cs index aa4111d3f3..f69494a859 100644 --- a/src/ServiceControl.Audit/Program.cs +++ b/src/ServiceControl.Audit/Program.cs @@ -40,7 +40,7 @@ } finally { - // Leave a trail in the logs to determine if the process was killed - NLog.LogManager.GetCurrentClassLogger().Info("Done!"); + // The following log statement is meant to leave a trail in the logs to determine if the process was killed + NLog.LogManager.GetCurrentClassLogger().Info("Shutdown complete"); NLog.LogManager.Shutdown(); } \ No newline at end of file diff --git a/src/ServiceControl.Monitoring/Program.cs b/src/ServiceControl.Monitoring/Program.cs index 8bd24b3382..872e659a9c 100644 --- a/src/ServiceControl.Monitoring/Program.cs +++ b/src/ServiceControl.Monitoring/Program.cs @@ -32,7 +32,7 @@ } finally { - // Leave a trail in the logs to determine if the process was killed - NLog.LogManager.GetCurrentClassLogger().Info("Done!"); + // The following log statement is meant to leave a trail in the logs to determine if the process was killed + NLog.LogManager.GetCurrentClassLogger().Info("Shutdown complete"); NLog.LogManager.Shutdown(); } \ No newline at end of file diff --git a/src/ServiceControl/Program.cs b/src/ServiceControl/Program.cs index b71c95a467..b5d0f3c63e 100644 --- a/src/ServiceControl/Program.cs +++ b/src/ServiceControl/Program.cs @@ -40,7 +40,7 @@ } finally { - // Leave a trail in the logs to determine if the process was killed - NLog.LogManager.GetCurrentClassLogger().Info("Done!"); + // The following log statement is meant to leave a trail in the logs to determine if the process was killed + NLog.LogManager.GetCurrentClassLogger().Info("Shutdown complete"); NLog.LogManager.Shutdown(); } \ No newline at end of file