-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
43 lines (35 loc) · 1.33 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
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace CloudflareDDNSUpdater;
internal class Program {
private static async Task Main() {
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
var serviceProvider = new ServiceCollection()
.AddLogging(builder => {
builder.AddSimpleConsole(options => {
options.TimestampFormat = "dd MMM hh:mm:ss ";
});
builder.AddConfiguration(configuration);
})
.AddTransient<DnsUpdater>()
.AddTransient(p => configuration)
.BuildServiceProvider();
while (true) {
var dnsUpdater = serviceProvider.GetService<DnsUpdater>();
var logger = serviceProvider.GetService<ILogger<Program>>();
try {
await dnsUpdater.Update();
}
catch (Exception ex) {
logger.LogError(ex, "Error during DNS update");
}
logger.LogTrace("Waiting for next update");
await Task.Delay(TimeSpan.FromMinutes(15));
}
}
}