Use Serilog in API
This commit is contained in:
		| @@ -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 => | ||||
|                     { | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -92,7 +92,13 @@ namespace PluralKit.Core | ||||
|  | ||||
|         protected override void Load(ContainerBuilder builder) | ||||
|         { | ||||
|             builder.Register(c => InitLogger(c.Resolve<CoreConfig>())).AsSelf().SingleInstance(); | ||||
|             builder | ||||
|                 .Register(c => InitLogger(c.Resolve<CoreConfig>())) | ||||
|                 .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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user