Add support for binding FormatterOptions from config file#124176
Add support for binding FormatterOptions from config file#124176mrek-msft merged 14 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds configuration-based binding support for EventLogSettings so Logging:EventLog:* values (e.g., SourceName) are applied when the EventLog provider is added via ILoggingBuilder (aligning behavior with other loggers like Console).
Changes:
- Enables configuration binding source generation for the EventLog logging project and adds the needed logging-configuration dependency.
- Registers an
IConfigureOptions<EventLogSettings>implementation (EventLogConfigureSettings) whenAddEventLog()is used. - Adds an internal
EventLogSettings.Configure(IConfiguration)helper that performs configuration binding.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj |
Enables config binding generator and adds references required for provider configuration binding. |
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs |
Wires EventLogConfigureSettings into DI when adding the provider. |
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs |
Adds internal configuration binding entry point for settings. |
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs |
New IConfigureOptions<EventLogSettings> to bind settings from provider configuration. |
...aries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ogConfigureSettings.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot review code skill |
…hangeTokenSource, remove unnecessary indirection
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs
Show resolved
Hide resolved
…mrek-msft/runtime into dev/mrek/mel-eventlog-bind-conf
src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs
Outdated
Show resolved
Hide resolved
|
/ba-g Test failures on most recent Build Analysis run are all known except one timeout which does not relate to changes in this PR. |
Code Review: PR #124176 - Add support for binding EventLogSettings from config fileHolistic AssessmentMotivation: This PR addresses a long-standing gap where EventLogSettings (SourceName, LogName, MachineName) could not be bound from configuration files, unlike other logging providers. This is a valid enhancement that aligns EventLog behavior with other providers like ConsoleLogger. Approach: The implementation follows the established pattern used by ConsoleLoggerConfigureOptions, registering an IConfigureOptions to bind configuration and adding IOptionsChangeTokenSource for configuration reload support. Source-generated configuration binding is enabled to support trimming. Net Positive: ✅ Yes - The changes address a real user need and follow established patterns. Detailed Findings
|
🤖 Copilot Code Review — PR #124176Holistic AssessmentMotivation: This PR addresses a long-standing gap (#80724) where Approach: The implementation follows the established pattern used by Summary: Detailed Findings
|
PR "fixes" (actually add missing support) #80724 WebApplication.CreateBuilder ignores Logging:EventLog:SourceName. It does not require any change to public facing API, but I consider it behavioral "breaking" change. Do I need to follow some process? (I am new in this repo). Implementation is done to be on par with Console loggers.
There are few points which brings some questions in advance:
EventLogConfigureSettingsto maintain convention, but we can consider EventLogConfigureOptions which will better indicate that it actually implements IConfigureOptions and will match Console logger convention. It is internal though.Fixes #80724