Skip to content

feat(aspnetcore): unified Serilog logging via AddSquidStdSerilog#24

Merged
tgiachi merged 7 commits into
developfrom
feature/aspnetcore-serilog
Jul 2, 2026
Merged

feat(aspnetcore): unified Serilog logging via AddSquidStdSerilog#24
tgiachi merged 7 commits into
developfrom
feature/aspnetcore-serilog

Conversation

@tgiachi

@tgiachi tgiachi commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in builder.AddSquidStdSerilog() so ASP.NET Core framework logs (Kestrel, Microsoft.Hosting.Lifetime) and SquidStd service logs share one Serilog logger, one configuration source (squidstd.yaml), and one console format.

Previously the SquidStd Serilog logger (configured late, in the hosted service) and the ASP.NET framework logger ran as two separate pipelines → two console formats. Wiring builder.Host.UseSerilog() naively broke framework logs because SquidStd sets Log.Logger after the framework has already captured the silent default.

Changes

  • SquidStdBootstrap / ISquidStdBootstrap: new public, idempotent ConfigureLogging() that eagerly loads the YAML config (IConfigManagerService.Load()) and builds Log.Logger once. _loggerConfigured now also guards the private ConfigureLogger(); StartAsync is unchanged (its late call becomes a no-op after the eager path).
  • SquidStd.AspNetCore: new builder.AddSquidStdSerilog() (sibling of AddSquidStdHealthChecks). After UseSquidStd, it resolves the bootstrap, calls ConfigureLogging(), then builder.Host.UseSerilog(Log.Logger, dispose: false). Throws if called before UseSquidStd. Adds Serilog.Extensions.Hosting 10.0.0.
  • Docs: module README + ASP.NET tutorial document the opt-in (with correct PascalCase YAML keys).

Not calling AddSquidStdSerilog() leaves behavior 100% unchanged. Console/worker hosts are untouched.

Test Plan

  • Bootstrap: eager config load + idempotency + eager-then-StartAsync builds logger once (3 tests)
  • AspNetCore: framework logging routed to SerilogLoggerFactory; opt-out keeps default factory; guard throws; double-call safe; behavioral test proving a framework ILogger<T> line reaches SquidStd's file sink (5 tests)
  • Full suite: 979/979 green
  • dotnet build SquidStd.slnx: 0 errors, 0 new warnings

public async Task AddSquidStdSerilog_RoutesFrameworkLogsToSquidStdFileSink()
{
using var temp = new TempDirectory();
var logDir = Path.Combine(temp.Path, "logs");
using var temp = new TempDirectory();
var logDir = Path.Combine(temp.Path, "logs");
File.WriteAllText(
Path.Combine(temp.Path, "app.yaml"),
@tgiachi
tgiachi merged commit eef0b2e into develop Jul 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants