feat: log to seq

This commit is contained in:
sam 2024-10-13 01:29:08 +02:00
parent d221441c10
commit ca99bdfb94
3 changed files with 11 additions and 0 deletions

View file

@ -32,6 +32,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
</ItemGroup>

View file

@ -16,6 +16,8 @@ public class Config
public int MetricsPort { get; init; } = 5001;
public bool EnableMetrics { get; init; } = true;
public string? SeqLogUrl { get; init; }
}
public class DatabaseConfig

View file

@ -48,6 +48,14 @@ public static class StartupExtensions
// The default theme doesn't support light mode
.WriteTo.Console(theme: AnsiConsoleTheme.Sixteen);
if (config.Logging.SeqLogUrl != null)
{
logCfg.WriteTo.Seq(
config.Logging.SeqLogUrl,
restrictedToMinimumLevel: LogEventLevel.Verbose
);
}
// AddSerilog doesn't seem to add an ILogger to the service collection, so add that manually.
builder.Services.AddSerilog().AddSingleton(Log.Logger = logCfg.CreateLogger());