-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgramFullControlDocker.cs
63 lines (55 loc) · 2.26 KB
/
ProgramFullControlDocker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace DotNetCoreGenericHostSample
{
public class ProgramFullControlDocker
{
public static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureLogging((hostContext, logging) =>
{
logging.AddConfiguration(hostContext.Configuration.GetSection("Logging"));
logging.AddConsole();
})
.ConfigureAppConfiguration((hostContext, config) =>
{
config.AddEnvironmentVariables();
config.AddJsonFile("appsettings.json", optional: true);
config.AddCommandLine(args);
})
.ConfigureServices((hostContext, services) =>
{
//services.AddHostedService<MyServiceA>();
//services.AddHostedService<MyServiceB>();
//services.AddHostedService<MyServiceC>();
services.AddHostedService<MyServiceX>();
services.AddHostedService<MyServiceY>();
services.AddHostedService<MyServiceZ>();
})
.Build();
var s = host.Services;
using (host)
{
Console.WriteLine("Starting!");
await host.StartAsync();
//Console.WriteLine("Started! Press <enter> to stop.");
Console.WriteLine("{0} : Started!", DateTime.Now.ToString());
// Console.ReadLine();
// Console.WriteLine("Stopping!");
// await host.StopAsync();
// Fixes issue in docker where any exception thrown is not in the container logs
try {
await host.WaitForShutdownAsync();
} catch(Exception ex) {
Console.WriteLine("{0} : Exception: {1}", DateTime.Now.ToString(), ex.ToString());
}
Console.WriteLine("{0} : Stopped!", DateTime.Now.ToString());
}
}
}
}