Add logger to API service setup
This commit is contained in:
parent
961bfe9094
commit
0b4335ccaa
@ -32,6 +32,7 @@ namespace PluralKit.API
|
|||||||
.AddScoped<TokenAuthService>()
|
.AddScoped<TokenAuthService>()
|
||||||
|
|
||||||
.AddTransient(_ => Configuration.GetSection("PluralKit").Get<CoreConfig>() ?? new CoreConfig())
|
.AddTransient(_ => Configuration.GetSection("PluralKit").Get<CoreConfig>() ?? new CoreConfig())
|
||||||
|
.AddSingleton(svc => InitUtils.InitLogger(svc.GetRequiredService<CoreConfig>(), "api"))
|
||||||
.AddSingleton(svc => new DbConnectionFactory(svc.GetRequiredService<CoreConfig>().Database));
|
.AddSingleton(svc => new DbConnectionFactory(svc.GetRequiredService<CoreConfig>().Database));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,18 +116,8 @@ namespace PluralKit.Bot
|
|||||||
})
|
})
|
||||||
.AddSingleton<PeriodicStatCollector>()
|
.AddSingleton<PeriodicStatCollector>()
|
||||||
|
|
||||||
.AddSingleton<ILogger>(svc => new LoggerConfiguration()
|
.AddSingleton(svc => InitUtils.InitLogger(svc.GetRequiredService<CoreConfig>(), "bot"))
|
||||||
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
|
.BuildServiceProvider();
|
||||||
.WriteTo.File(
|
|
||||||
new CompactJsonFormatter(),
|
|
||||||
(svc.GetRequiredService<CoreConfig>().LogDir ?? "logs") + "/pluralkit.bot.log",
|
|
||||||
rollingInterval: RollingInterval.Day,
|
|
||||||
flushToDiskInterval: TimeSpan.FromSeconds(10),
|
|
||||||
buffered: true)
|
|
||||||
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
|
|
||||||
.CreateLogger())
|
|
||||||
|
|
||||||
.BuildServiceProvider();
|
|
||||||
}
|
}
|
||||||
class Bot
|
class Bot
|
||||||
{
|
{
|
||||||
|
@ -15,10 +15,6 @@
|
|||||||
<PackageReference Include="Discord.Net.WebSocket" Version="2.0.1" />
|
<PackageReference Include="Discord.Net.WebSocket" Version="2.0.1" />
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.6.2" />
|
<PackageReference Include="Humanizer.Core" Version="2.6.2" />
|
||||||
<PackageReference Include="Sentry" Version="2.0.0-beta2" />
|
<PackageReference Include="Sentry" Version="2.0.0-beta2" />
|
||||||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
|
|
||||||
<PackageReference Include="Serilog.NodaTime" Version="1.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
|
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
<PackageReference Include="Npgsql" Version="4.0.6" />
|
<PackageReference Include="Npgsql" Version="4.0.6" />
|
||||||
<PackageReference Include="Npgsql.NodaTime" Version="4.0.6" />
|
<PackageReference Include="Npgsql.NodaTime" Version="4.0.6" />
|
||||||
<PackageReference Include="Serilog" Version="2.8.0" />
|
<PackageReference Include="Serilog" Version="2.8.0" />
|
||||||
|
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Serilog.NodaTime" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -13,6 +13,9 @@ using NodaTime;
|
|||||||
using NodaTime.Serialization.JsonNet;
|
using NodaTime.Serialization.JsonNet;
|
||||||
using NodaTime.Text;
|
using NodaTime.Text;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Formatting.Compact;
|
||||||
|
using Serilog.Sinks.SystemConsole.Themes;
|
||||||
|
|
||||||
|
|
||||||
namespace PluralKit
|
namespace PluralKit
|
||||||
@ -299,6 +302,20 @@ namespace PluralKit
|
|||||||
SqlMapper.AddTypeHandler(new PassthroughTypeHandler<LocalDate>());
|
SqlMapper.AddTypeHandler(new PassthroughTypeHandler<LocalDate>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ILogger InitLogger(CoreConfig config, string component)
|
||||||
|
{
|
||||||
|
return new LoggerConfiguration()
|
||||||
|
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
|
||||||
|
.WriteTo.File(
|
||||||
|
new CompactJsonFormatter(),
|
||||||
|
(config.LogDir ?? "logs") + $"/pluralkit.{component}.log",
|
||||||
|
rollingInterval: RollingInterval.Day,
|
||||||
|
flushToDiskInterval: TimeSpan.FromSeconds(10),
|
||||||
|
buffered: true)
|
||||||
|
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
|
||||||
|
.CreateLogger();
|
||||||
|
}
|
||||||
|
|
||||||
public static JsonSerializerSettings BuildSerializerSettings() => new JsonSerializerSettings().BuildSerializerSettings();
|
public static JsonSerializerSettings BuildSerializerSettings() => new JsonSerializerSettings().BuildSerializerSettings();
|
||||||
|
|
||||||
public static JsonSerializerSettings BuildSerializerSettings(this JsonSerializerSettings settings)
|
public static JsonSerializerSettings BuildSerializerSettings(this JsonSerializerSettings settings)
|
||||||
|
Loading…
Reference in New Issue
Block a user