-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (41 loc) · 1.27 KB
/
Program.cs
File metadata and controls
51 lines (41 loc) · 1.27 KB
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
using Serilog;
using SocialSifter;
using SocialSifter.Destinations;
using SocialSifter.Interfaces;
using SocialSifter.Services;
using SocialSifter.Sources;
var builder = Host.CreateApplicationBuilder(args);
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.CreateLogger();
builder.Services.AddSerilog();
// Configure options
builder.Services.Configure<SocialSifterOptions>(
builder.Configuration.GetSection("SocialSifter"));
// Register message processor
builder.Services.AddSingleton<MessageProcessor>();
// Register sources
builder.Services.AddSingleton<ISocialMediaSource, RedditSource>();
builder.Services.AddSingleton<ISocialMediaSource, DiscordSource>();
// Register destinations
builder.Services.AddSingleton<IPublishDestination, DiscordPublisher>();
// Register hosted service
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
try
{
Log.Information("Starting SocialSifter service");
host.Run();
Log.Information("SocialSifter service stopped cleanly");
}
catch (Exception ex)
{
Log.Fatal(ex, "SocialSifter service terminated unexpectedly");
throw;
}
finally
{
Log.CloseAndFlush();
}