-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
57 lines (48 loc) · 2.13 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 Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NetSuiteRestApiOAuth2.Jobs;
using Quartz;
using Serilog;
using Serilog.Events;
namespace NetSuiteRestApiOAuth2
{
internal class Program
{
static void Main(string[] args)
{
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
var logfile = Path.Combine(baseDir, "Logs", "log.txt");
const string loggerTemplate = @"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u1}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File(logfile, LogEventLevel.Information, loggerTemplate,
rollingInterval: RollingInterval.Day, retainedFileCountLimit: 21)
.CreateLogger();
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureServices((hostContext, services) =>
{
services.AddHttpClient<NetSuiteTokenClient>();
services.AddTransient<NetSuiteAuthHandler>();
services.AddHttpClient<NetSuiteApiClient>()
.AddHttpMessageHandler<NetSuiteAuthHandler>();
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
q.ScheduleJob<ExampleJob>(trigger => trigger
.WithIdentity("ExampleTrigger")
.StartAt(DateBuilder.EvenSecondDate(DateTimeOffset.UtcNow.AddSeconds(6)))
.WithDailyTimeIntervalSchedule(x => x.WithInterval(10, IntervalUnit.Second))
);
});
services.AddQuartzHostedService(options =>
{
options.WaitForJobsToComplete = true;
});
});
}
}