feat(aspnetcore): unified Serilog logging via AddSquidStdSerilog#24
Merged
Conversation
| 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"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 setsLog.Loggerafter the framework has already captured the silent default.Changes
SquidStdBootstrap/ISquidStdBootstrap: new public, idempotentConfigureLogging()that eagerly loads the YAML config (IConfigManagerService.Load()) and buildsLog.Loggeronce._loggerConfigurednow also guards the privateConfigureLogger();StartAsyncis unchanged (its late call becomes a no-op after the eager path).SquidStd.AspNetCore: newbuilder.AddSquidStdSerilog()(sibling ofAddSquidStdHealthChecks). AfterUseSquidStd, it resolves the bootstrap, callsConfigureLogging(), thenbuilder.Host.UseSerilog(Log.Logger, dispose: false). Throws if called beforeUseSquidStd. AddsSerilog.Extensions.Hosting10.0.0.Not calling
AddSquidStdSerilog()leaves behavior 100% unchanged. Console/worker hosts are untouched.Test Plan
StartAsyncbuilds logger once (3 tests)SerilogLoggerFactory; opt-out keeps default factory; guard throws; double-call safe; behavioral test proving a frameworkILogger<T>line reaches SquidStd's file sink (5 tests)dotnet build SquidStd.slnx: 0 errors, 0 new warnings