From a48e354a36d8a2445b4c3452cfa041d40432c154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 9 Feb 2026 13:52:55 +0100 Subject: [PATCH 01/13] Add support for binding FormatterOptions from config file. --- .../src/EventLogConfigureSettings.cs | 31 +++++++++++++++++++ .../src/EventLogExtensions.cs | 19 ++++++++++++ .../src/EventLogSettings.cs | 3 ++ .../src/EventLoggerFactoryExtensions.cs | 3 ++ ...crosoft.Extensions.Logging.EventLog.csproj | 10 +++++- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs create mode 100644 src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs new file mode 100644 index 00000000000000..cccb68a3bd76fb --- /dev/null +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging.Configuration; +using Microsoft.Extensions.Logging.EventLog; +using Microsoft.Extensions.Options; + +namespace Microsoft.Extensions.Logging +{ + /// + /// Configures a EventLogSettings object from an IConfiguration. + /// + /// + /// Doesn't use ConfigurationBinder in order to allow ConfigurationBinder, and all its dependencies, + /// to be trimmed. This improves app size and startup. + /// + internal sealed class EventLogConfigureSettings : IConfigureOptions + { + private readonly IConfiguration _configuration; + + [UnsupportedOSPlatform("browser")] + public EventLogConfigureSettings(ILoggerProviderConfiguration providerConfiguration) + { + _configuration = providerConfiguration.GetFormatterOptionsSection(); + } + + public void Configure(EventLogSettings options) => options.Configure(_configuration); + } +} diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs new file mode 100644 index 00000000000000..50d936ad2425ef --- /dev/null +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging.Configuration; +using Microsoft.Extensions.Logging.EventLog; + +namespace Microsoft.Extensions.Logging +{ + [UnsupportedOSPlatform("browser")] + internal static partial class EventLogExtensions + { + internal static IConfiguration GetFormatterOptionsSection(this ILoggerProviderConfiguration providerConfiguration) + { + return providerConfiguration.Configuration.GetSection("FormatterOptions"); + } + } +} diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs index c361d41d6ec64b..1fb86839a429ac 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using Microsoft.Extensions.Configuration; namespace Microsoft.Extensions.Logging.EventLog { @@ -53,5 +54,7 @@ private WindowsEventLog CreateDefaultEventLog() return new WindowsEventLog(logName, machineName, sourceName) { DefaultEventId = defaultEventId }; } + + internal void Configure(IConfiguration configuration) => configuration.Bind(this); } } diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs index ef7123df898f8c..150d140bce9910 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging.EventLog; +using Microsoft.Extensions.Options; namespace Microsoft.Extensions.Logging { @@ -58,6 +59,7 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder) ArgumentNullException.ThrowIfNull(builder); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogConfigureSettings>()); return builder; } @@ -74,6 +76,7 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder, EventLog ArgumentNullException.ThrowIfNull(settings); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton(new EventLogLoggerProvider(settings))); + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogConfigureSettings>()); return builder; } diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj index ebe0f0b2e24993..01c16c0ed08ebd 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) @@ -7,6 +7,9 @@ Windows Event Log logger provider implementation for Microsoft.Extensions.Logging. false + true + + $(NoWarn);SYSLIB1100;SYSLIB1101 @@ -17,9 +20,14 @@ + + From f24d368df5d44d3a55a75fdb3ddfd6dbe1805d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:09:19 +0100 Subject: [PATCH 02/13] Do not require FormatterOptions configuration section nesting. --- .../src/EventLogExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs index 50d936ad2425ef..555869f3772f7e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs @@ -13,7 +13,7 @@ internal static partial class EventLogExtensions { internal static IConfiguration GetFormatterOptionsSection(this ILoggerProviderConfiguration providerConfiguration) { - return providerConfiguration.Configuration.GetSection("FormatterOptions"); + return providerConfiguration.Configuration; } } } From 0952641f7ee65d39f5999cfb705e48f1ec9a8705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:13:07 +0100 Subject: [PATCH 03/13] Clenup after removal need for FormatterOptions scope --- .../src/EventLogConfigureSettings.cs | 2 +- .../src/EventLogExtensions.cs | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs index cccb68a3bd76fb..ee8768da5945f7 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -23,7 +23,7 @@ internal sealed class EventLogConfigureSettings : IConfigureOptions providerConfiguration) { - _configuration = providerConfiguration.GetFormatterOptionsSection(); + _configuration = providerConfiguration.Configuration; } public void Configure(EventLogSettings options) => options.Configure(_configuration); diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs deleted file mode 100644 index 555869f3772f7e..00000000000000 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Runtime.Versioning; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging.Configuration; -using Microsoft.Extensions.Logging.EventLog; - -namespace Microsoft.Extensions.Logging -{ - [UnsupportedOSPlatform("browser")] - internal static partial class EventLogExtensions - { - internal static IConfiguration GetFormatterOptionsSection(this ILoggerProviderConfiguration providerConfiguration) - { - return providerConfiguration.Configuration; - } - } -} From 6a22c031ffa034aa0107381efd6b36641b547f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:31:45 +0100 Subject: [PATCH 04/13] Revert whitespace BOM change --- .../src/Microsoft.Extensions.Logging.EventLog.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj index 01c16c0ed08ebd..04ba40081ca4d1 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) From 347410b14ea2e83b3fea7243b572e78825b24342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:45:35 +0100 Subject: [PATCH 05/13] Fix grammar in comment --- .../src/EventLogConfigureSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs index ee8768da5945f7..486e43f2f0dc72 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Logging { /// - /// Configures a EventLogSettings object from an IConfiguration. + /// Configures an EventLogSettings object from an IConfiguration. /// /// /// Doesn't use ConfigurationBinder in order to allow ConfigurationBinder, and all its dependencies, From dd1411ab18f7241409322d1bfee6a7a907d1f337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:48:23 +0100 Subject: [PATCH 06/13] Add missing InterceptorsPreviewNamespaces --- .../src/Microsoft.Extensions.Logging.EventLog.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj index 04ba40081ca4d1..a309d8982ec22b 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj @@ -7,6 +7,7 @@ Windows Event Log logger provider implementation for Microsoft.Extensions.Logging. false + $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration true $(NoWarn);SYSLIB1100;SYSLIB1101 From 4087eafd0401be2565a7b53c825da020c9d37888 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Date: Mon, 9 Feb 2026 07:47:19 -0800 Subject: [PATCH 07/13] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/EventLogConfigureSettings.cs | 2 +- .../src/Microsoft.Extensions.Logging.EventLog.csproj | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs index ee8768da5945f7..486e43f2f0dc72 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Logging { /// - /// Configures a EventLogSettings object from an IConfiguration. + /// Configures an EventLogSettings object from an IConfiguration. /// /// /// Doesn't use ConfigurationBinder in order to allow ConfigurationBinder, and all its dependencies, diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj index 04ba40081ca4d1..260b2787ade82e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj @@ -8,6 +8,7 @@ false true + $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration $(NoWarn);SYSLIB1100;SYSLIB1101 From fcc0be21993966ad6a7d996ba977b2d8cb77c17b Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:20:32 -0800 Subject: [PATCH 08/13] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/EventLogConfigureSettings.cs | 4 ++-- .../src/EventLoggerFactoryExtensions.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs index 486e43f2f0dc72..6af6f839be04a8 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -13,8 +13,8 @@ namespace Microsoft.Extensions.Logging /// Configures an EventLogSettings object from an IConfiguration. /// /// - /// Doesn't use ConfigurationBinder in order to allow ConfigurationBinder, and all its dependencies, - /// to be trimmed. This improves app size and startup. + /// Applies configuration to via , + /// which uses the ConfigurationBinder APIs under the hood. /// internal sealed class EventLogConfigureSettings : IConfigureOptions { diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs index 150d140bce9910..d6eebcee7557be 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs @@ -76,7 +76,7 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder, EventLog ArgumentNullException.ThrowIfNull(settings); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton(new EventLogLoggerProvider(settings))); - builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogConfigureSettings>()); + return builder; } From 936c60767022b62d06680cdd83901a4d75bea1ed Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:03:44 -0800 Subject: [PATCH 09/13] Update src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> From b6e1ec30016dbb77df156a12c2dc5df8052c2574 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Mon, 9 Feb 2026 09:48:33 -0800 Subject: [PATCH 10/13] Fix EventLog configuration binding: add AddConfiguration(), IOptionsChangeTokenSource, remove unnecessary indirection --- .../src/EventLogConfigureSettings.cs | 6 +++--- .../src/EventLogSettings.cs | 3 --- .../src/EventLoggerFactoryExtensions.cs | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs index 6af6f839be04a8..b2d73a0bf37f4e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -13,8 +13,8 @@ namespace Microsoft.Extensions.Logging /// Configures an EventLogSettings object from an IConfiguration. /// /// - /// Applies configuration to via , - /// which uses the ConfigurationBinder APIs under the hood. + /// Doesn't use ConfigurationBinder in order to allow ConfigurationBinder, and all its dependencies, + /// to be trimmed. This improves app size and startup. /// internal sealed class EventLogConfigureSettings : IConfigureOptions { @@ -26,6 +26,6 @@ public EventLogConfigureSettings(ILoggerProviderConfiguration options.Configure(_configuration); + public void Configure(EventLogSettings options) => _configuration.Bind(options); } } diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs index 1fb86839a429ac..c361d41d6ec64b 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.Extensions.Configuration; namespace Microsoft.Extensions.Logging.EventLog { @@ -54,7 +53,5 @@ private WindowsEventLog CreateDefaultEventLog() return new WindowsEventLog(logName, machineName, sourceName) { DefaultEventId = defaultEventId }; } - - internal void Configure(IConfiguration configuration) => configuration.Bind(this); } } diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs index d6eebcee7557be..55494d95840d7c 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Logging.Configuration; using Microsoft.Extensions.Logging.EventLog; using Microsoft.Extensions.Options; @@ -58,8 +59,10 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder) { ArgumentNullException.ThrowIfNull(builder); + builder.AddConfiguration(); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogConfigureSettings>()); + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, LoggerProviderOptionsChangeTokenSource>()); return builder; } @@ -77,7 +80,6 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder, EventLog builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton(new EventLogLoggerProvider(settings))); - return builder; } From 3ebb335af592dad671123c17b58346c587a12f19 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Mon, 9 Feb 2026 10:14:14 -0800 Subject: [PATCH 11/13] Fix XML remarks comment and add configuration binding tests --- .../src/EventLogConfigureSettings.cs | 2 +- .../tests/Common/EventLogLoggerTest.cs | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs index b2d73a0bf37f4e..1cd29792ed070a 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs @@ -13,7 +13,7 @@ namespace Microsoft.Extensions.Logging /// Configures an EventLogSettings object from an IConfiguration. /// /// - /// Doesn't use ConfigurationBinder in order to allow ConfigurationBinder, and all its dependencies, + /// Uses source-generated configuration binding to allow ConfigurationBinder, and all its dependencies, /// to be trimmed. This improves app size and startup. /// internal sealed class EventLogConfigureSettings : IConfigureOptions diff --git a/src/libraries/Microsoft.Extensions.Logging/tests/Common/EventLogLoggerTest.cs b/src/libraries/Microsoft.Extensions.Logging/tests/Common/EventLogLoggerTest.cs index 88dbc4c4b8ec56..c28afede65a536 100644 --- a/src/libraries/Microsoft.Extensions.Logging/tests/Common/EventLogLoggerTest.cs +++ b/src/libraries/Microsoft.Extensions.Logging/tests/Common/EventLogLoggerTest.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.EventLog; using Xunit; @@ -126,6 +127,55 @@ public void IOptions_CreatesWindowsEventLog_WithSuppliedEventLogSettings() Assert.Equal("blah", settings.MachineName); } + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] + public void AddEventLog_SettingsFromConfiguration_IsReadFromLoggingConfiguration() + { + var configuration = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Logging:EventLog:SourceName", "TestSource"), + new KeyValuePair("Logging:EventLog:LogName", "TestLog"), + new KeyValuePair("Logging:EventLog:MachineName", "TestMachine"), + }).Build(); + + var serviceCollection = new ServiceCollection(); + serviceCollection.AddLogging(builder => builder + .AddConfiguration(configuration.GetSection("Logging")) + .AddEventLog()); + + var services = serviceCollection.BuildServiceProvider(); + var provider = (EventLogLoggerProvider)(services.GetRequiredService>().First()); + var settings = provider._settings; + Assert.Equal("TestLog", settings.LogName); + Assert.Equal("TestSource", settings.SourceName); + Assert.Equal("TestMachine", settings.MachineName); + } + + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] + public void AddEventLog_SettingsFromConfiguration_ActionOverridesConfigValues() + { + var configuration = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Logging:EventLog:SourceName", "ConfigSource"), + new KeyValuePair("Logging:EventLog:LogName", "ConfigLog"), + }).Build(); + + var serviceCollection = new ServiceCollection(); + serviceCollection.AddLogging(builder => builder + .AddConfiguration(configuration.GetSection("Logging")) + .AddEventLog(options => + { + options.SourceName = "ActionSource"; + })); + + var services = serviceCollection.BuildServiceProvider(); + var provider = (EventLogLoggerProvider)(services.GetRequiredService>().First()); + var settings = provider._settings; + Assert.Equal("ActionSource", settings.SourceName); + Assert.Equal("ConfigLog", settings.LogName); + } + [Theory] [PlatformSpecific(TestPlatforms.Windows)] [InlineData(50)] From 6a7b989779fa601a503470677ba0727847d48984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Tue, 10 Feb 2026 15:41:02 +0100 Subject: [PATCH 12/13] Target copilot PR comment: rename settings to options. --- ...entLogConfigureSettings.cs => EventLogConfigureOptions.cs} | 4 ++-- .../src/EventLoggerFactoryExtensions.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/libraries/Microsoft.Extensions.Logging.EventLog/src/{EventLogConfigureSettings.cs => EventLogConfigureOptions.cs} (82%) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureOptions.cs similarity index 82% rename from src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs rename to src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureOptions.cs index 1cd29792ed070a..57a42125d1c2d2 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureSettings.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogConfigureOptions.cs @@ -16,12 +16,12 @@ namespace Microsoft.Extensions.Logging /// Uses source-generated configuration binding to allow ConfigurationBinder, and all its dependencies, /// to be trimmed. This improves app size and startup. /// - internal sealed class EventLogConfigureSettings : IConfigureOptions + internal sealed class EventLogConfigureOptions : IConfigureOptions { private readonly IConfiguration _configuration; [UnsupportedOSPlatform("browser")] - public EventLogConfigureSettings(ILoggerProviderConfiguration providerConfiguration) + public EventLogConfigureOptions(ILoggerProviderConfiguration providerConfiguration) { _configuration = providerConfiguration.Configuration; } diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs index 55494d95840d7c..79f5c8f91e17d2 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLoggerFactoryExtensions.cs @@ -61,7 +61,7 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder) builder.AddConfiguration(); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); - builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogConfigureSettings>()); + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogConfigureOptions>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, LoggerProviderOptionsChangeTokenSource>()); return builder; From 31eea2ccd12426472d28df437f2eae21d1d78891 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:52:43 -0800 Subject: [PATCH 13/13] Remove property duplication in the csproj --- .../src/Microsoft.Extensions.Logging.EventLog.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj index 92949ef8aa8c47..260b2787ade82e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.EventLog/src/Microsoft.Extensions.Logging.EventLog.csproj @@ -7,7 +7,6 @@ Windows Event Log logger provider implementation for Microsoft.Extensions.Logging. false - $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration true $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration