|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | using System;
|
| 16 | +using System.Reflection; |
16 | 17 | using Microsoft.Extensions.Configuration;
|
17 | 18 | using Microsoft.Extensions.DependencyModel;
|
18 | 19 | using Serilog.Configuration;
|
@@ -169,5 +170,39 @@ public static LoggerConfiguration ConfigurationSection(
|
169 | 170 |
|
170 | 171 | return settingConfiguration.Settings(new ConfigurationReader(configSection, assemblyFinder, configuration: null));
|
171 | 172 | }
|
| 173 | + |
| 174 | + /// <summary> |
| 175 | + /// Reads logger settings from the provided configuration object using the provided section name. |
| 176 | + /// </summary> |
| 177 | + /// <param name="settingConfiguration">Logger setting configuration.</param> |
| 178 | + /// <param name="configuration">A configuration object which contains a Serilog section.</param> |
| 179 | + /// <param name="sectionName">A section name for section which contains a Serilog section.</param> |
| 180 | + /// <param name="assemblies">A collection of assemblies that contains sinks and other Types.</param> |
| 181 | + /// <returns>An object allowing configuration to continue.</returns> |
| 182 | + public static LoggerConfiguration Configuration( |
| 183 | + this LoggerSettingsConfiguration settingConfiguration, |
| 184 | + IConfiguration configuration, |
| 185 | + string sectionName, |
| 186 | + params Assembly[] assemblies) |
| 187 | + { |
| 188 | + if (settingConfiguration == null) throw new ArgumentNullException(nameof(settingConfiguration)); |
| 189 | + if (configuration == null) throw new ArgumentNullException(nameof(configuration)); |
| 190 | + if (sectionName == null) throw new ArgumentNullException(nameof(sectionName)); |
| 191 | + |
| 192 | + return settingConfiguration.Settings(new ConfigurationReader(configuration.GetSection(sectionName), assemblies, new ResolutionContext(configuration))); |
| 193 | + } |
| 194 | + |
| 195 | + /// <summary> |
| 196 | + /// Reads logger settings from the provided configuration object using the default section name. |
| 197 | + /// </summary> |
| 198 | + /// <param name="settingConfiguration">Logger setting configuration.</param> |
| 199 | + /// <param name="configuration">A configuration object which contains a Serilog section.</param> |
| 200 | + /// <param name="assemblies">A collection of assemblies that contains sinks and other Types.</param> |
| 201 | + /// <returns>An object allowing configuration to continue.</returns> |
| 202 | + public static LoggerConfiguration Configuration( |
| 203 | + this LoggerSettingsConfiguration settingConfiguration, |
| 204 | + IConfiguration configuration, |
| 205 | + params Assembly[] assemblies) |
| 206 | + => Configuration(settingConfiguration, configuration, DefaultSectionName, assemblies); |
172 | 207 | }
|
173 | 208 | }
|
0 commit comments