feat: ILoggingBuilder.AddSerilog() extension method#3013
Draft
feat: ILoggingBuilder.AddSerilog() extension method#3013
Conversation
Context: #3008 Context: #3011 Context: unoplatform/uno.templates#1921 Issue #3008 details that there are two `ILogger` "environments" in a Uno app: * The `App.InitializeLogging()` environment ("NoDI"), and * The environment configured by Dependency Injection methods such as `.UseLogging()` and `.UseSerilog()` ("DI"). The problem is that "DI" logging *cannot* capture log messages produced before the DI environment is built, frequently via `builder.Build()` or `builder.NavigateAsync<TShell>()`. *A lot* of code can execute before those methods complete. A further problem is that no default template actually configures both environments: if you use `dotnet new unoapp -di False` you get the NoDI `App.InitializeLogging()` environment, which *will not* log messages from the Dependency Injection enviornment. If you use `dotnet new unoapp -preset "recommended"` you get *only* the DI-based logging, thus missing all messages from the NoDI environment. Thus, the idea for "`ILogger` configuration unification": What If instead of having two separate places for logging, we just had one: the NoDI `App.InitializeLogging()` location. This can be made to work via #3011, which updates `HostBuilder.Build()` so that *if* `LogExtensionPoint.AmbientLoggerFactory` is set, it *replaces* the `ILoggerFactory` that `HostBuilder.Build()` normally configures. This allows `App.InitializeLogging()` to also be used in the DI environment. So far, so useful. But what about [Serilog][0]? Serilog is a widely recommended logger library, and the current `.UseSerilog()` extension method *requires* a full Dependency Injection environment: it cannot be invoked within `App.InitializeLogging()`. Try to square this circle by adding a new `ILoggingBuilder.AddSerilog()` extension method. This would allow Serilog to be configured within `App.InitializeLogging()`, helping to support a unified logging setup experience. [0]: https://platform.uno/docs/articles/external/uno.extensions/doc/Overview/Logging/LoggingOverview.html#serilog
Contributor
Author
|
TODO/question to consider: what would be the replacement for |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-moss-0c5b8040f-3013.eastus2.azurestaticapps.net |
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.
Context: #3008
Context: #3011
Context: unoplatform/uno.templates#1921
Issue #3008 details that there are two
ILogger"environments" in a Uno app:App.InitializeLogging()environment ("NoDI"), and.UseLogging()and.UseSerilog()("DI").The problem is that "DI" logging cannot capture log messages produced before the DI environment is built, frequently via
builder.Build()orbuilder.NavigateAsync<TShell>(). A lot of code can execute before those methods complete.A further problem is that no default template actually configures both environments: if you use
dotnet new unoapp -di Falseyou get the NoDIApp.InitializeLogging()environment, which will not log messages from the Dependency Injection enviornment. If you usedotnet new unoapp -preset "recommended"you get only the DI-based logging, thus missing all messages from the NoDI environment.Thus, the idea for "
ILoggerconfiguration unification": What If instead of having two separate places for logging, we just had one: the NoDIApp.InitializeLogging()location.This can be made to work via #3011, which updates
HostBuilder.Build()so that ifLogExtensionPoint.AmbientLoggerFactoryis set, it replaces theILoggerFactorythatHostBuilder.Build()normally configures. This allowsApp.InitializeLogging()to also be used in the DI environment.So far, so useful.
But what about Serilog? Serilog is a widely recommended logger library, and the current
.UseSerilog()extension method requires a full Dependency Injection environment: it cannot be invoked withinApp.InitializeLogging().Try to square this circle by adding a new
ILoggingBuilder.AddSerilog()extension method. This would allow Serilog to be configured withinApp.InitializeLogging(), helping to support a unified logging setup experience.GitHub Issue (If applicable): closes #
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
Internal Issue (If applicable):