-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (57 loc) · 2.55 KB
/
Program.cs
File metadata and controls
61 lines (57 loc) · 2.55 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
52
53
54
55
56
57
58
59
60
61
using System.Reflection;
using AltGen;
using AltGen.Config;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Compact;
using Serilog.Sinks.Grafana.Loki;
using Mastodon = AltGen.Mastodon;
internal class Program
{
private static void Main(string[] args)
{
var serviceProvider = CreateServiceProvider();
var looper = serviceProvider.GetRequiredService<Looper>();
looper.Loop().Wait();
}
private static IServiceProvider CreateServiceProvider()
{
var services = new ServiceCollection();
services.AddSingleton<Secrets>(
Newtonsoft.Json.JsonConvert.DeserializeObject<AltGen.Config.Secrets>(File.ReadAllText("secrets.json")) ??
throw new Exception("Cannot read config"));
services.AddScoped<Mastodon>();
services.AddScoped<OpenAiAltGen>();
services.AddScoped<Looper>();
services.AddLogging(cfg => cfg.SetMinimumLevel(LogLevel.Debug));
services.AddSerilog(cfg =>
{
cfg.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithProperty("job", Assembly.GetEntryAssembly()?.GetName().Name)
.Enrich.WithProperty("service", Assembly.GetEntryAssembly()?.GetName().Name)
.Enrich.WithProperty("desktop", Environment.GetEnvironmentVariable("DESKTOP_SESSION"))
.Enrich.WithProperty("language", Environment.GetEnvironmentVariable("LANGUAGE"))
.Enrich.WithProperty("lc", Environment.GetEnvironmentVariable("LC_NAME"))
.Enrich.WithProperty("timezone", Environment.GetEnvironmentVariable("TZ"))
.Enrich.WithProperty("dotnetVersion", Environment.GetEnvironmentVariable("DOTNET_VERSION"))
.Enrich.WithProperty("inContainer",
Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"))
.WriteTo.GrafanaLoki(Environment.GetEnvironmentVariable("LOKIURL") ?? "http://thebeast:3100",
propertiesAsLabels: ["job"]);
if (Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyConfigurationAttribute>()?.Configuration ==
"Debug")
{
cfg.WriteTo.Console(new RenderedCompactJsonFormatter());
}
else
{
cfg.WriteTo.Console();
}
});
return services.BuildServiceProvider();
}
}