1- using System ;
2- using System . Linq ;
31using Microsoft . Extensions . Configuration ;
42using Microsoft . Extensions . Logging ;
53
@@ -21,6 +19,18 @@ public static void LogProviderNamesAsInformation(this ILogger logger, IConfigura
2119 logger . LogProviderNames ( config , LogLevel . Information ) ;
2220 }
2321
22+ /// <summary>
23+ /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
24+ /// at the Information log level.
25+ /// </summary>
26+ /// <param name="config">The configuration root to examine.</param>
27+ /// <param name="logger">The logger to write the results to.</param>
28+ /// <param name="options">The options to use for rendering the provider names.</param>
29+ public static void LogProviderNamesAsInformation ( this ILogger logger , IConfigurationRoot config , ConfigurationDiagnosticsOptions options )
30+ {
31+ logger . LogProviderNames ( config , LogLevel . Information , options ) ;
32+ }
33+
2434 /// <summary>
2535 /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
2636 /// at the Debug log level.
@@ -32,6 +42,18 @@ public static void LogProviderNamesAsDebug(this ILogger logger, IConfigurationRo
3242 logger . LogProviderNames ( config , LogLevel . Debug ) ;
3343 }
3444
45+ /// <summary>
46+ /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
47+ /// at the Debug log level.
48+ /// </summary>
49+ /// <param name="config">The configuration root to examine.</param>
50+ /// <param name="logger">The logger to write the results to.</param>
51+ /// <param name="options">The options to use for rendering the provider names.</param>
52+ public static void LogProviderNamesAsDebug ( this ILogger logger , IConfigurationRoot config , ConfigurationDiagnosticsOptions options )
53+ {
54+ logger . LogProviderNames ( config , LogLevel . Debug , options ) ;
55+ }
56+
3557 /// <summary>
3658 /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
3759 /// at the Trace log level.
@@ -43,6 +65,18 @@ public static void LogProviderNamesAsTrace(this ILogger logger, IConfigurationRo
4365 logger . LogProviderNames ( config , LogLevel . Trace ) ;
4466 }
4567
68+ /// <summary>
69+ /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
70+ /// at the Trace log level.
71+ /// </summary>
72+ /// <param name="config">The configuration root to examine.</param>
73+ /// <param name="logger">The logger to write the results to.</param>
74+ /// <param name="options">The options to use for rendering the provider names.</param>
75+ public static void LogProviderNamesAsTrace ( this ILogger logger , IConfigurationRoot config , ConfigurationDiagnosticsOptions options )
76+ {
77+ logger . LogProviderNames ( config , LogLevel . Trace , options ) ;
78+ }
79+
4680 /// <summary>
4781 /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
4882 /// </summary>
@@ -51,12 +85,24 @@ public static void LogProviderNamesAsTrace(this ILogger logger, IConfigurationRo
5185 /// <param name="level">The log level to use.</param>
5286 public static void LogProviderNames ( this ILogger logger , IConfigurationRoot config , LogLevel level )
5387 {
54- var providerNames = config . Providers
55- . Select ( p => p . GetType ( ) . FullName ) ;
56- string message = "The following configuration providers were registered:" +
57- Environment . NewLine +
58- string . Join ( Environment . NewLine , providerNames ) ;
59- logger . Log ( level , message ) ;
88+ logger . LogProviderNames ( config , level , ConfigurationDiagnosticsOptions . GlobalOptions ) ;
89+ }
90+
91+ /// <summary>
92+ /// Logs the provider names in the given <see cref="T:Microsoft.Extensions.Configuration.IConfigurationRoot"/>
93+ /// </summary>
94+ /// <param name="config">The configuration root to examine.</param>
95+ /// <param name="logger">The logger to write the results to.</param>
96+ /// <param name="level">The log level to use.</param>
97+ /// <param name="options">The options to use for rendering the provider names.</param>
98+ public static void LogProviderNames (
99+ this ILogger logger ,
100+ IConfigurationRoot config ,
101+ LogLevel level ,
102+ ConfigurationDiagnosticsOptions options )
103+ {
104+ var message = options . ConfigurationProviderNameRenderer . Render ( config ) ;
105+ logger . Log ( message . GetLogLevel ( level ) , message . Exception , message . MessageTemplate , message . Properties ) ;
60106 }
61107
62108 /// <summary>
@@ -68,6 +114,17 @@ public static void LogProvidersAsInformation(this ILogger logger, IConfiguration
68114 {
69115 logger . LogProviders ( config , LogLevel . Information ) ;
70116 }
117+
118+ /// <summary>
119+ /// Logs a list of the providers the configuration is using at the Information level.
120+ /// </summary>
121+ /// <param name="logger">The logger to write the details to.</param>
122+ /// <param name="config">The configuration root.</param>
123+ /// <param name="options">The options to use for rendering the providers.</param>
124+ public static void LogProvidersAsInformation ( this ILogger logger , IConfigurationRoot config , ConfigurationDiagnosticsOptions options )
125+ {
126+ logger . LogProviders ( config , LogLevel . Information , options ) ;
127+ }
71128
72129 /// <summary>
73130 /// Logs a list of the providers the configuration is using at the Debug level.
@@ -79,6 +136,17 @@ public static void LogProvidersAsDebug(this ILogger logger, IConfigurationRoot c
79136 logger . LogProviders ( config , LogLevel . Debug ) ;
80137 }
81138
139+ /// <summary>
140+ /// Logs a list of the providers the configuration is using at the Debug level.
141+ /// </summary>
142+ /// <param name="logger">The logger to write the details to.</param>
143+ /// <param name="config">The configuration root.</param>
144+ /// <param name="options">The options to use for rendering the providers.</param>
145+ public static void LogProvidersAsDebug ( this ILogger logger , IConfigurationRoot config , ConfigurationDiagnosticsOptions options )
146+ {
147+ logger . LogProviders ( config , LogLevel . Debug , options ) ;
148+ }
149+
82150 /// <summary>
83151 /// Logs a list of the providers the configuration is using at the Trace level.
84152 /// </summary>
@@ -89,6 +157,17 @@ public static void LogProvidersAsTrace(this ILogger logger, IConfigurationRoot c
89157 logger . LogProviders ( config , LogLevel . Trace ) ;
90158 }
91159
160+ /// <summary>
161+ /// Logs a list of the providers the configuration is using at the Trace level.
162+ /// </summary>
163+ /// <param name="logger">The logger to write the details to.</param>
164+ /// <param name="config">The configuration root.</param>
165+ /// <param name="options">The options to use for rendering the providers.</param>
166+ public static void LogProvidersAsTrace ( this ILogger logger , IConfigurationRoot config , ConfigurationDiagnosticsOptions options )
167+ {
168+ logger . LogProviders ( config , LogLevel . Trace , options ) ;
169+ }
170+
92171 /// <summary>
93172 /// Logs a list of the providers the configuration is using.
94173 /// </summary>
@@ -97,12 +176,24 @@ public static void LogProvidersAsTrace(this ILogger logger, IConfigurationRoot c
97176 /// <param name="level">The level to log at.</param>
98177 public static void LogProviders ( this ILogger logger , IConfigurationRoot config , LogLevel level )
99178 {
100- var providers = config . Providers
101- . Select ( p => p . ToString ( ) ) ;
102- string message = "The following configuration providers were registered:" +
103- Environment . NewLine +
104- string . Join ( Environment . NewLine , providers ) ;
105- logger . Log ( level , message ) ;
179+ logger . LogProviders ( config , level , ConfigurationDiagnosticsOptions . GlobalOptions ) ;
180+ }
181+
182+ /// <summary>
183+ /// Logs a list of the providers the configuration is using.
184+ /// </summary>
185+ /// <param name="logger">The logger to write the details to.</param>
186+ /// <param name="config">The configuration root.</param>
187+ /// <param name="level">The level to log at.</param>
188+ /// <param name="options">The options to use for rendering the providers.</param>
189+ public static void LogProviders (
190+ this ILogger logger ,
191+ IConfigurationRoot config ,
192+ LogLevel level ,
193+ ConfigurationDiagnosticsOptions options )
194+ {
195+ var message = options . ConfigurationProviderRenderer . Render ( config ) ;
196+ logger . Log ( message . GetLogLevel ( level ) , message . Exception , message . MessageTemplate , message . Properties ) ;
106197 }
107198 }
108199}
0 commit comments