AddProvider checks for non-null provider
6.0 RC 1
Previously, AddProvider(ILoggerProvider) did not perform any validation of the
provider argument. As such, the method considered
null to be a "valid" provider and added it to the collection of providers.
Starting in .NET 6,
null providers aren't accepted, and AddProvider(ILoggerProvider) throws an ArgumentNullException if the logging provider argument is
null. For example, the following code throws an ArgumentNullException:
var factory = new LoggerFactory(); ((ILoggerFactory)factory).AddProvider(null));
Type of breaking change
This change can affect source compatibility.
Reason for change
The previous behavior caused some operations inside the class to unnecessarily throw NullReferenceException exceptions. For example, the LoggerFactory.Dispose() method will capture the exception and do nothing.
Ensure you're not passing a
null provider to AddProvider(ILoggerProvider).