-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
The current example for ColorConsoleLoggerProvider which usesIOptionsMonitor<ColorConsoleLoggerConfiguration> doesn't update the config for existing loggers that have already been instantiated and stored in _loggers. When the configuration changes, these loggers continue to reference the old ColorConsoleLoggerConfiguration instance and only the new instances take on the configuration change.
One suggestion to fix this is to update the following line in the constructor from;
_onChangeToken = config.OnChange(updatedConfig => _currentConfig = updatedConfig);to;
_onChangeToken = config.OnChange(updatedConfig =>
{
_currentConfig = updatedConfig;
_loggers.Clear();
});Other than that, I'm wondering if there are best practices that other developers like me should know about when implementing a custom logging provider. For example, how to make an async HTTP request to a logging backend.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: b609eb80-71e8-7a3c-4c4c-60cf9a315cfb
- Version Independent ID: e111baf5-04b7-c497-ce86-eb687e121751
- Content: Implement a custom logging provider in .NET
- Content Source: docs/core/extensions/custom-logging-provider.md
- Product: dotnet-fundamentals
- GitHub Login: @IEvangelist
- Microsoft Alias: dapine