Open xxAtrain223 opened 5 months ago
Response from GitHub Copilot:
The statement is partially correct. When you use
AddEventLog
with theEventLogSettings
overload, it creates a new instance ofEventLogLoggerProvider
with the provided settings. If there's already anEventLogLoggerProvider
instance registered (which would be the case if you didn't callbuilder.Logging.ClearProviders()
), the new settings won't replace the existing ones.However, the second part of the statement is not entirely accurate. The
Action<EventLogSettings>
overload ofAddEventLog
doesn't replace the settings of an existingEventLogLoggerProvider
instance either. Instead, it modifies the settings of theEventLogLoggerProvider
instance that's being added.So, if you want to ensure that your
EventLogSettings
are used, you should callbuilder.Logging.ClearProviders()
before callingAddEventLog
. If you don't clear the providers and there's already anEventLogLoggerProvider
registered, neither overload ofAddEventLog
will replace the existing settings.
Please note that there has been confusion from this since 2021: https://github.com/dotnet/runtime/issues/51899
Description
Please clarify that when using
AddEventLog
, theEventLogSettings
overload should only be used ifbuilder.Logging.ClearProviders();
was called, otherwise the new EventLogSettings doesn't get used. And that if you don'tClearProviders
, then theAction<EventLogSettings>
overload should be used.Page URL
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-8.0#welog
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/logging/index.md
Document ID
726e3bf1-f367-d733-8933-bccc04da0e16
Article author
@tdykstra
Associated WorkItem - 261933