Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default ILoggingBuilder extension #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

snargledorf
Copy link

For situations where configuration is under the default "Logging" section. Also accepts an optional configure options action.

Usage: loggingBuilder.AddFile()

@snargledorf
Copy link
Author

snargledorf commented Sep 19, 2024

I did just think of something that is pushing me to close this pull request.

With this implementation, in the event the "File" configuration is not present under the "Logging" configuration, the CreateFromConfiguration method will return null. This causes an exception to be thrown when building the service collection.

The expectation for default extensions such as this is that it will construct the service (In this case an ILoggerProvider) with a default configuration. Since don't have a default path for the log file, we cannot setup a logging provider with a default configuration.

Unless in the future a default log file is defined, this has the potential to break apps unintentionally when changing logging configuration (IE. Removing the "File" section), which shouldn't happen.

@snargledorf
Copy link
Author

snargledorf commented Sep 19, 2024

I updated the PR with a potential solution.

Now if the FileLoggerProvider fails to be built, a NullLoggerProvider is returned in its place. This isn't my favorite solution, but it does technically fix the exception and is more in line with expected behavior.

Removed the FileLoggerProvider TImplementation so that NullLoggerProvider can be returned by the implementation factory method.
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.

1 participant