Use asynchronous logging

This commit is contained in:
Ske 2019-12-23 00:29:30 +01:00
parent 05282fd167
commit b4ad1e5041
2 changed files with 11 additions and 8 deletions

View File

@ -22,6 +22,7 @@
<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.Async" Version="1.4.1-dev-00071" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
</ItemGroup>

View File

@ -323,14 +323,16 @@ namespace PluralKit
return new LoggerConfiguration()
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
.MinimumLevel.Debug()
.WriteTo.File(
.WriteTo.Async(a =>
a.File(
new RenderedCompactJsonFormatter(),
(config.LogDir ?? "logs") + $"/pluralkit.{component}.log",
rollingInterval: RollingInterval.Day,
flushToDiskInterval: TimeSpan.FromSeconds(10),
restrictedToMinimumLevel: LogEventLevel.Information,
buffered: true)
.WriteTo.Console(theme: AnsiConsoleTheme.Code, outputTemplate:"[{Timestamp:HH:mm:ss}] [{EventId}] {Level:u3} {Message:lj}{NewLine}{Exception}")
buffered: true))
.WriteTo.Async(a =>
a.Console(theme: AnsiConsoleTheme.Code, outputTemplate:"[{Timestamp:HH:mm:ss}] [{EventId}] {Level:u3} {Message:lj}{NewLine}{Exception}"))
.CreateLogger();
}