mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
Use Serilog in API
This commit is contained in:
parent
3617d5e894
commit
f89ca4c867
3 changed files with 11 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue