-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgramHelloWorldDocker.cs
54 lines (49 loc) · 2.02 KB
/
ProgramHelloWorldDocker.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
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 ProgramHelloWorldDocker
{
public static async Task Main(string[] args)
{
//var builder = Host.CreateDefaultBuilder() // dotnet 3.0 only
var builder = 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>();
});
// dotnet 3.0 only
// await builder.RunConsoleAsync(options =>
// {
// options.SuppressStatusMessages = false;
// });
// Attempt to fix issue in docker where any exception thrown is not in the container logs
// This does not work here, only the exception is still not shown
try {
await builder.RunConsoleAsync();
} catch(Exception ex) {
Console.WriteLine("{0} : Exception: {1}", DateTime.Now.ToString(), ex.ToString());
}
}
}
}