diff --git a/test/Polly.Extensions.Tests/Issues/IssuesTests.OverrideLoggerFactory_1783.cs b/test/Polly.Extensions.Tests/Issues/IssuesTests.OverrideLoggerFactory_1783.cs new file mode 100644 index 00000000000..54276d5ca2c --- /dev/null +++ b/test/Polly.Extensions.Tests/Issues/IssuesTests.OverrideLoggerFactory_1783.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Logging; +using Polly.Registry; + +namespace Polly.Extensions.Tests.Issues; + +public partial class IssuesTests +{ + [Fact] + public void OverrideLoggerFactory_ByExplicitConfigureTelemetryCall_1783() + { + // Arrange + using var loggerFactory1 = new FakeLoggerFactory(); + using var loggerFactory2 = new FakeLoggerFactory(); + var services = new ServiceCollection(); + services.TryAddSingleton(loggerFactory1); + + // Act + services.AddResiliencePipeline("dummy", builder => + { + builder.AddTimeout(TimeSpan.FromSeconds(1)); + + // This call should override the base factory + builder.ConfigureTelemetry(loggerFactory2); + }); + + // Assert + var provider = services.BuildServiceProvider().GetRequiredService>(); + + provider.GetPipeline("dummy").Execute(() => { }); + + loggerFactory1.FakeLogger.GetRecords().Should().BeEmpty(); + loggerFactory2.FakeLogger.GetRecords().Should().NotBeEmpty(); + } +}