-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
57 lines (51 loc) · 1.69 KB
/
Program.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
using docker_hosts_writer;
using System.Diagnostics;
// Windows event log variable
const string windowsEventSourceName = "Docker Hosts Writer (Worker)";
const string windowsEventLogName = "Docker Hosts Writer";
var isWindows = OperatingSystem.IsWindows();
if (isWindows)
{
// Create event log
if (!EventLog.SourceExists(windowsEventSourceName))
EventLog.CreateEventSource(new EventSourceCreationData(windowsEventSourceName, windowsEventLogName));
}
// Parsing arguments
CommandLines commands = new CommandLines() { Args = args };
CommandLines.Options options = commands.Parse();
IHost host = Host.CreateDefaultBuilder(args)
.UseWindowsService(options =>
{
options.ServiceName = "Docker Hosts Writer";
})
.UseSystemd()
.ConfigureLogging(log =>
{
log.AddSimpleConsole(options =>
{
options.SingleLine = true;
options.TimestampFormat = "yyyy-MM-dd HH:mm:ss ";
});
if (isWindows)
{
log.AddEventLog(options =>
{
options.SourceName = windowsEventSourceName;
options.LogName = windowsEventLogName;
});
}
// Verbose command only work without appsettings.json
// Log level in appsettings.json has higher priority
if (options.Verbose)
log.SetMinimumLevel(LogLevel.Debug);
else
log.SetMinimumLevel(LogLevel.Information);
})
.ConfigureServices(services =>
{
services.AddSingleton(commands);
services.AddSingleton<Hosts>();
services.AddHostedService<Worker>();
})
.Build();
await host.RunAsync();