Commit 19e6555 1 parent f7d296a commit 19e6555 Copy full SHA for 19e6555
File tree 3 files changed +33
-2
lines changed
ExcelRna.Extensions.Logging
ExcelRna.Extensions.Logging.Tests
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
+ using System . Linq ;
2
3
using Microsoft . Extensions . DependencyInjection ;
3
4
using Microsoft . Extensions . Logging ;
4
5
using Xunit ;
@@ -17,6 +18,20 @@ public void AddLogDisplay_adds_logger()
17
18
. GetRequiredService < IEnumerable < ILoggerProvider > > ( ) ;
18
19
19
20
// ASSERT
20
- Assert . Contains ( providers , provider => provider is LogDisplayLoggerProvider ) ;
21
+ Assert . Single ( providers . OfType < LogDisplayLoggerProvider > ( ) ) ;
22
+ }
23
+
24
+ [ Fact ]
25
+ public void AddLogDisplay_adds_logger_with_options ( )
26
+ {
27
+ // ARRANGE & ACT
28
+ var providers = new ServiceCollection ( )
29
+ . AddLogging ( logging => logging . AddLogDisplay ( options => options . AutoShowLogDisplayThreshold = LogLevel . Information ) )
30
+ . BuildServiceProvider ( )
31
+ . GetRequiredService < IEnumerable < ILoggerProvider > > ( ) ;
32
+
33
+ // ASSERT
34
+ LogDisplayLoggerProvider provider = Assert . Single ( providers . OfType < LogDisplayLoggerProvider > ( ) ) ;
35
+ Assert . Equal ( LogLevel . Information , provider . Options . AutoShowLogDisplayThreshold ) ;
21
36
}
22
37
}
Original file line number Diff line number Diff line change
1
+ using System ;
1
2
using Microsoft . Extensions . DependencyInjection ;
2
3
using Microsoft . Extensions . DependencyInjection . Extensions ;
3
4
using Microsoft . Extensions . Logging ;
@@ -10,7 +11,7 @@ namespace ExcelRna.Extensions.Logging;
10
11
public static class LogDisplayLoggerFactoryExtensions
11
12
{
12
13
/// <summary>
13
- /// Adds a debug logger named 'LogDisplay' to the factory.
14
+ /// Adds a LogDisplay logger named 'LogDisplay' to the factory.
14
15
/// </summary>
15
16
/// <param name="builder">The extension method argument.</param>
16
17
public static ILoggingBuilder AddLogDisplay ( this ILoggingBuilder builder )
@@ -19,4 +20,17 @@ public static ILoggingBuilder AddLogDisplay(this ILoggingBuilder builder)
19
20
20
21
return builder ;
21
22
}
23
+
24
+ /// <summary>
25
+ /// Adds a LogDisplay logger named 'LogDisplay' to the factory.
26
+ /// </summary>
27
+ /// <param name="builder">The extension method argument.</param>
28
+ /// <param name="configureOptions">The action used to configure the options.</param>
29
+ public static ILoggingBuilder AddLogDisplay ( this ILoggingBuilder builder , Action < LogDisplayLoggerOptions > configureOptions )
30
+ {
31
+ builder . Services . Configure ( configureOptions ) ;
32
+ builder . Services . TryAddEnumerable ( ServiceDescriptor . Singleton < ILoggerProvider , LogDisplayLoggerProvider > ( ) ) ;
33
+
34
+ return builder ;
35
+ }
22
36
}
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ public LogDisplayLoggerProvider(IOptionsMonitor<LogDisplayLoggerOptions> options
22
22
_optionsReloadToken = options . OnChange ( ReloadOptions ) ;
23
23
}
24
24
25
+ internal LogDisplayLoggerOptions Options => _options . CurrentValue ;
26
+
25
27
/// <inheritdoc />
26
28
public ILogger CreateLogger ( string name )
27
29
{
You can’t perform that action at this time.
0 commit comments