diff --git a/Source/ExcelRna.Extensions.Logging.Tests/LogDisplayLoggerFactoryExtensionsTests.cs b/Source/ExcelRna.Extensions.Logging.Tests/LogDisplayLoggerFactoryExtensionsTests.cs index 1466e77..805ec09 100644 --- a/Source/ExcelRna.Extensions.Logging.Tests/LogDisplayLoggerFactoryExtensionsTests.cs +++ b/Source/ExcelRna.Extensions.Logging.Tests/LogDisplayLoggerFactoryExtensionsTests.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Xunit; @@ -17,6 +18,20 @@ public void AddLogDisplay_adds_logger() .GetRequiredService>(); // ASSERT - Assert.Contains(providers, provider => provider is LogDisplayLoggerProvider); + Assert.Single(providers.OfType()); + } + + [Fact] + public void AddLogDisplay_adds_logger_with_options() + { + // ARRANGE & ACT + var providers = new ServiceCollection() + .AddLogging(logging => logging.AddLogDisplay(options => options.AutoShowLogDisplayThreshold = LogLevel.Information)) + .BuildServiceProvider() + .GetRequiredService>(); + + // ASSERT + LogDisplayLoggerProvider provider = Assert.Single(providers.OfType()); + Assert.Equal(LogLevel.Information, provider.Options.AutoShowLogDisplayThreshold); } } diff --git a/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerFactoryExtensions.cs b/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerFactoryExtensions.cs index 6967c63..de5338d 100644 --- a/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerFactoryExtensions.cs +++ b/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerFactoryExtensions.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; @@ -10,7 +11,7 @@ namespace ExcelRna.Extensions.Logging; public static class LogDisplayLoggerFactoryExtensions { /// - /// Adds a debug logger named 'LogDisplay' to the factory. + /// Adds a LogDisplay logger named 'LogDisplay' to the factory. /// /// The extension method argument. public static ILoggingBuilder AddLogDisplay(this ILoggingBuilder builder) @@ -19,4 +20,17 @@ public static ILoggingBuilder AddLogDisplay(this ILoggingBuilder builder) return builder; } + + /// + /// Adds a LogDisplay logger named 'LogDisplay' to the factory. + /// + /// The extension method argument. + /// The action used to configure the options. + public static ILoggingBuilder AddLogDisplay(this ILoggingBuilder builder, Action configureOptions) + { + builder.Services.Configure(configureOptions); + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); + + return builder; + } } diff --git a/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerProvider.cs b/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerProvider.cs index b2f5583..47aa0b2 100644 --- a/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerProvider.cs +++ b/Source/ExcelRna.Extensions.Logging/LogDisplayLoggerProvider.cs @@ -22,6 +22,8 @@ public LogDisplayLoggerProvider(IOptionsMonitor options _optionsReloadToken = options.OnChange(ReloadOptions); } + internal LogDisplayLoggerOptions Options => _options.CurrentValue; + /// public ILogger CreateLogger(string name) {