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" Version="2.8.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" /> <PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
<PackageReference Include="Serilog.NodaTime" 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.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
</ItemGroup> </ItemGroup>

View File

@ -323,14 +323,16 @@ namespace PluralKit
return new LoggerConfiguration() return new LoggerConfiguration()
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb) .ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
.MinimumLevel.Debug() .MinimumLevel.Debug()
.WriteTo.File( .WriteTo.Async(a =>
new RenderedCompactJsonFormatter(), a.File(
(config.LogDir ?? "logs") + $"/pluralkit.{component}.log", new RenderedCompactJsonFormatter(),
rollingInterval: RollingInterval.Day, (config.LogDir ?? "logs") + $"/pluralkit.{component}.log",
flushToDiskInterval: TimeSpan.FromSeconds(10), rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: LogEventLevel.Information, flushToDiskInterval: TimeSpan.FromSeconds(10),
buffered: true) restrictedToMinimumLevel: LogEventLevel.Information,
.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(); .CreateLogger();
} }