diff --git a/PluralKit.API/Program.cs b/PluralKit.API/Program.cs index 2e3725cd..7f7b7133 100644 --- a/PluralKit.API/Program.cs +++ b/PluralKit.API/Program.cs @@ -6,6 +6,8 @@ using Microsoft.Extensions.Hosting; using PluralKit.Core; +using Serilog; + namespace PluralKit.API { public class Program @@ -19,8 +21,8 @@ namespace PluralKit.API public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .UseSerilog() .ConfigureWebHostDefaults(whb => whb - .UseConfiguration(InitUtils.BuildConfiguration(args).Build()) .ConfigureKestrel(opts => { diff --git a/PluralKit.API/Startup.cs b/PluralKit.API/Startup.cs index 810cc041..0549b312 100644 --- a/PluralKit.API/Startup.cs +++ b/PluralKit.API/Startup.cs @@ -15,7 +15,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; -using PluralKit.API; using PluralKit.Core; namespace PluralKit.API diff --git a/PluralKit.Core/Modules.cs b/PluralKit.Core/Modules.cs index 1cf358d8..c82acac0 100644 --- a/PluralKit.Core/Modules.cs +++ b/PluralKit.Core/Modules.cs @@ -92,7 +92,13 @@ namespace PluralKit.Core protected override void Load(ContainerBuilder builder) { - builder.Register(c => InitLogger(c.Resolve())).AsSelf().SingleInstance(); + builder + .Register(c => InitLogger(c.Resolve())) + .AsSelf() + .SingleInstance() + // AutoActivate ensures logging is enabled as early as possible in the API startup flow + // since we set the Log.Logger global >.> + .AutoActivate(); } private ILogger InitLogger(CoreConfig config) @@ -103,6 +109,7 @@ namespace PluralKit.Core var logCfg = new LoggerConfiguration() .Enrich.FromLogContext() .ConfigureForNodaTime(DateTimeZoneProviders.Tzdb) + .Enrich.WithProperty("Component", _component) .MinimumLevel.Is(config.ConsoleLogLevel) // Actual formatting for these is handled in ScalarFormatting