Skip to content

Commit 341696d

Browse files
committed
Log when application is done to determine if process was killed
1 parent ba4fb02 commit 341696d

File tree

3 files changed

+79
-52
lines changed

3 files changed

+79
-52
lines changed

src/ServiceControl.Audit/Program.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,40 @@
77
using ServiceControl.Configuration;
88
using ServiceControl.Infrastructure;
99

10-
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
10+
try
11+
{
12+
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
1113

12-
// Hack: See https://github.com/Particular/ServiceControl/issues/4392
13-
var exitCode = await IntegratedSetup.Run();
14+
// Hack: See https://github.com/Particular/ServiceControl/issues/4392
15+
var exitCode = await IntegratedSetup.Run();
1416

15-
if (exitCode != 0)
16-
{
17-
return exitCode;
18-
}
17+
if (exitCode != 0)
18+
{
19+
return exitCode;
20+
}
1921

20-
ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());
22+
ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());
2123

22-
var arguments = new HostArguments(args);
24+
var arguments = new HostArguments(args);
2325

24-
if (arguments.Help)
25-
{
26-
arguments.PrintUsage();
27-
return 0;
28-
}
26+
if (arguments.Help)
27+
{
28+
arguments.PrintUsage();
29+
return 0;
30+
}
2931

30-
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace);
31-
LoggingConfigurator.ConfigureLogging(loggingSettings);
32+
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace);
33+
LoggingConfigurator.ConfigureLogging(loggingSettings);
3234

33-
var settings = new Settings(loggingSettings: loggingSettings);
35+
var settings = new Settings(loggingSettings: loggingSettings);
3436

35-
await new CommandRunner(arguments.Command).Execute(arguments, settings);
37+
await new CommandRunner(arguments.Command).Execute(arguments, settings);
3638

37-
return 0;
39+
return 0;
40+
}
41+
finally
42+
{
43+
// Leave a trail in the logs to determine if the process was killed
44+
NLog.LogManager.GetCurrentClassLogger().Info("Done!");
45+
NLog.LogManager.Shutdown();
46+
}

src/ServiceControl.Monitoring/Program.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@
55
using ServiceControl.Infrastructure;
66
using ServiceControl.Monitoring;
77

8-
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
8+
try
9+
{
10+
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
911

10-
// Hack: See https://github.com/Particular/ServiceControl/issues/4392
11-
var exitCode = await IntegratedSetup.Run();
12+
// Hack: See https://github.com/Particular/ServiceControl/issues/4392
13+
var exitCode = await IntegratedSetup.Run();
1214

13-
if (exitCode != 0)
14-
{
15-
return exitCode;
16-
}
15+
if (exitCode != 0)
16+
{
17+
return exitCode;
18+
}
1719

18-
ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());
20+
ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());
1921

20-
var arguments = new HostArguments(args);
22+
var arguments = new HostArguments(args);
2123

22-
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace);
23-
LoggingConfigurator.ConfigureLogging(loggingSettings);
24+
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace);
25+
LoggingConfigurator.ConfigureLogging(loggingSettings);
2426

25-
var settings = new Settings(loggingSettings: loggingSettings);
27+
var settings = new Settings(loggingSettings: loggingSettings);
2628

27-
await new CommandRunner(arguments.Command).Execute(arguments, settings);
29+
await new CommandRunner(arguments.Command).Execute(arguments, settings);
2830

29-
return 0;
31+
return 0;
32+
}
33+
finally
34+
{
35+
// Leave a trail in the logs to determine if the process was killed
36+
NLog.LogManager.GetCurrentClassLogger().Info("Done!");
37+
NLog.LogManager.Shutdown();
38+
}

src/ServiceControl/Program.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,40 @@
77
using ServiceControl.Hosting.Commands;
88
using ServiceControl.Infrastructure;
99

10-
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
10+
try
11+
{
12+
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
1113

12-
// Hack: See https://github.com/Particular/ServiceControl/issues/4392
13-
var exitCode = await IntegratedSetup.Run();
14+
// Hack: See https://github.com/Particular/ServiceControl/issues/4392
15+
var exitCode = await IntegratedSetup.Run();
1416

15-
if (exitCode != 0)
16-
{
17-
return exitCode;
18-
}
17+
if (exitCode != 0)
18+
{
19+
return exitCode;
20+
}
1921

20-
ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());
22+
ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());
2123

22-
var arguments = new HostArguments(args);
24+
var arguments = new HostArguments(args);
2325

24-
if (arguments.Help)
25-
{
26-
arguments.PrintUsage();
27-
return 0;
28-
}
26+
if (arguments.Help)
27+
{
28+
arguments.PrintUsage();
29+
return 0;
30+
}
2931

30-
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace);
31-
LoggingConfigurator.ConfigureLogging(loggingSettings);
32+
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace);
33+
LoggingConfigurator.ConfigureLogging(loggingSettings);
3234

33-
var settings = new Settings(loggingSettings: loggingSettings);
35+
var settings = new Settings(loggingSettings: loggingSettings);
3436

35-
await new CommandRunner(arguments.Command).Execute(arguments, settings);
37+
await new CommandRunner(arguments.Command).Execute(arguments, settings);
3638

37-
return 0;
39+
return 0;
40+
}
41+
finally
42+
{
43+
// Leave a trail in the logs to determine if the process was killed
44+
NLog.LogManager.GetCurrentClassLogger().Info("Done!");
45+
NLog.LogManager.Shutdown();
46+
}

0 commit comments

Comments
 (0)