Use Serilog in API
This commit is contained in:
parent
3617d5e894
commit
f89ca4c867
@ -6,6 +6,8 @@ using Microsoft.Extensions.Hosting;
|
|||||||
|
|
||||||
using PluralKit.Core;
|
using PluralKit.Core;
|
||||||
|
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace PluralKit.API
|
namespace PluralKit.API
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
@ -19,8 +21,8 @@ namespace PluralKit.API
|
|||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||||
Host.CreateDefaultBuilder(args)
|
Host.CreateDefaultBuilder(args)
|
||||||
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
||||||
|
.UseSerilog()
|
||||||
.ConfigureWebHostDefaults(whb => whb
|
.ConfigureWebHostDefaults(whb => whb
|
||||||
|
|
||||||
.UseConfiguration(InitUtils.BuildConfiguration(args).Build())
|
.UseConfiguration(InitUtils.BuildConfiguration(args).Build())
|
||||||
.ConfigureKestrel(opts =>
|
.ConfigureKestrel(opts =>
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
using PluralKit.API;
|
|
||||||
using PluralKit.Core;
|
using PluralKit.Core;
|
||||||
|
|
||||||
namespace PluralKit.API
|
namespace PluralKit.API
|
||||||
|
@ -92,7 +92,13 @@ namespace PluralKit.Core
|
|||||||
|
|
||||||
protected override void Load(ContainerBuilder builder)
|
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)
|
private ILogger InitLogger(CoreConfig config)
|
||||||
@ -103,6 +109,7 @@ namespace PluralKit.Core
|
|||||||
var logCfg = new LoggerConfiguration()
|
var logCfg = new LoggerConfiguration()
|
||||||
.Enrich.FromLogContext()
|
.Enrich.FromLogContext()
|
||||||
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
|
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
|
||||||
|
.Enrich.WithProperty("Component", _component)
|
||||||
.MinimumLevel.Is(config.ConsoleLogLevel)
|
.MinimumLevel.Is(config.ConsoleLogLevel)
|
||||||
|
|
||||||
// Actual formatting for these is handled in ScalarFormatting
|
// Actual formatting for these is handled in ScalarFormatting
|
||||||
|
Loading…
Reference in New Issue
Block a user