Use Serilog in API

This commit is contained in:
Ske
2020-08-27 23:36:02 +02:00
parent 3617d5e894
commit f89ca4c867
3 changed files with 11 additions and 3 deletions

View File

@@ -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