PluralKit/PluralKit.API/Program.cs
alyssa 09ed215e6c
Some checks failed
Build and push Docker image / .net docker build (push) Has been cancelled
.net checks / run .net tests (push) Has been cancelled
.net checks / dotnet-format (push) Has been cancelled
chore: clean up .net sentry exceptions
2026-01-25 06:53:15 -05:00

51 lines
No EOL
1.6 KiB
C#

using Autofac.Extensions.DependencyInjection;
using PluralKit.Core;
using Sentry;
using Serilog;
namespace PluralKit.API;
public class Program
{
public static async Task Main(string[] args)
{
InitUtils.InitStatic();
await BuildInfoService.LoadVersion();
var host = CreateHostBuilder(args).Build();
var config = host.Services.GetRequiredService<CoreConfig>();
// Initialize Sentry SDK, and make sure it gets dropped at the end
using var _ = SentrySdk.Init(opts =>
{
opts.Dsn = config.SentryUrl ?? "";
opts.Release = BuildInfoService.FullVersion;
opts.AutoSessionTracking = true;
opts.DisableUnobservedTaskExceptionCapture();
});
TaskScheduler.UnobservedTaskException += (_, e) =>
{
foreach (var inner in e.Exception.Flatten().InnerExceptions)
SentrySdk.CaptureException(inner);
e.SetObserved();
};
await host.Services.GetRequiredService<RedisService>().InitAsync(config);
await host.RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.UseSerilog()
.ConfigureWebHostDefaults(whb => whb
.UseConfiguration(InitUtils.BuildConfiguration(args).Build())
.ConfigureKestrel(opts =>
{
opts.ListenAnyIP(opts.ApplicationServices.GetRequiredService<ApiConfig>().Port);
})
.UseStartup<Startup>());
}