SerilogBestPractices: retarget net10.0, switch to AddSerilog, fix level moniker width - #2122
Open
vladimir-pecanac-main wants to merge 2 commits into
Conversation
…el moniker width
- Retarget both projects to net10.0.
- builder.Host.UseSerilog(...) -> builder.Services.AddSerilog(...), the form
serilog-aspnetcore now documents. The lambda receives an IServiceProvider
instead of a HostBuilderContext, so the configuration is re-sourced from
builder.Configuration.
- appsettings.json output template: {Level:u11} -> {Level:u3}. The width is a
maximum, not a field width, so u11 printed every level in full (INFORMATION,
WARNING) instead of the conventional aligned INF/WRN/ERR.
- Move .MinimumLevel.Information() above the sinks in the bootstrap
configuration so it reads configuration-then-destinations. Chain order does
not affect behaviour; both are consumed inside CreateLogger().
- Bring packages current: Serilog 4.4.0, Serilog.AspNetCore 10.0.0,
Serilog.Settings.Configuration 10.0.1, Serilog.Enrichers.Thread 4.0.0,
Serilog.Enrichers.Process 3.0.0, Serilog.Enrichers.Environment 3.0.1,
Serilog.Sinks.Console 6.1.1, Serilog.Sinks.Seq 9.1.0,
Serilog.Enrichers.ClientInfo 2.9.0, Microsoft.AspNetCore.OpenApi 10.0.11,
Microsoft.AspNetCore.Mvc.Testing 10.0.11.
- Swashbuckle.AspNetCore 6.4.0 -> 10.2.3. 6.4.0 throws TypeLoadException from
SwaggerGenerator.GetSwagger against Microsoft.OpenApi 2.0.0 on net10.0, and
the sample's own catch-all disguises it as a host that never got built.
The host now replaces the startup logger once appsettings.json is read, which is the two-stage initialization serilog-aspnetcore documents. CreateLogger() left the static Log.Logger pinned to the pre-host configuration.
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.
Updates the
dotnet-logging/SerilogBestPracticessample for the refreshed Serilog Best Practices for Logging in .NET article.net10.0.builder.Host.UseSerilog(...)->builder.Services.AddSerilog(...), the formserilog-aspnetcorenow documents. Not a one-for-one rename: the lambda receives anIServiceProviderinstead of aHostBuilderContext, so the configuration is re-sourced frombuilder.Configuration.appsettings.jsonoutput template{Level:u11}->{Level:u3}. The number is a maximum width, not a field width, sou11printed every level in full (INFORMATION,WARNING) rather than the conventional alignedINF/WRN/ERR..MinimumLevel.Information()above the sinks in the bootstrap configuration (readability only; both are consumed insideCreateLogger(), so chain order does not affect behaviour).net10.0the old version throwsTypeLoadExceptionfromSwaggerGenerator.GetSwaggeragainst Microsoft.OpenApi 2.0.0, and the sample's own catch-all disguises that as a host that never got built.dotnet build -c Releasesucceeds anddotnet testpasses 1/1 on .NET 10.0.10.