@@ -32,34 +32,53 @@ public static class ConfigurationLoggerConfigurationExtensions
32
32
public const string DefaultSectionName = "Serilog" ;
33
33
34
34
/// <summary>
35
- /// Reads logger settings from the provided configuration object using the default section name. Generally this
35
+ /// Reads logger settings from the provided configuration object using the provided section name. Generally this
36
36
/// is preferable over the other method that takes a configuration section. Only this version will populate
37
37
/// IConfiguration parameters on target methods.
38
38
/// </summary>
39
39
/// <param name="settingConfiguration">Logger setting configuration.</param>
40
40
/// <param name="configuration">A configuration object which contains a Serilog section.</param>
41
+ /// <param name="sectionName">A section name for section which contains a Serilog section.</param>
41
42
/// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
42
43
/// default will be used.</param>
43
44
/// <returns>An object allowing configuration to continue.</returns>
44
45
public static LoggerConfiguration Configuration (
45
46
this LoggerSettingsConfiguration settingConfiguration ,
46
47
IConfiguration configuration ,
48
+ string sectionName ,
47
49
DependencyContext dependencyContext = null )
48
50
{
49
51
if ( settingConfiguration == null ) throw new ArgumentNullException ( nameof ( settingConfiguration ) ) ;
50
52
if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
53
+ if ( sectionName == null ) throw new ArgumentNullException ( nameof ( sectionName ) ) ;
51
54
52
55
var assemblyFinder = dependencyContext == null
53
56
? AssemblyFinder . Auto ( )
54
57
: AssemblyFinder . ForDependencyContext ( dependencyContext ) ;
55
58
56
59
return settingConfiguration . Settings (
57
60
new ConfigurationReader (
58
- configuration . GetSection ( DefaultSectionName ) ,
61
+ configuration . GetSection ( sectionName ) ,
59
62
assemblyFinder ,
60
63
configuration ) ) ;
61
64
}
62
65
66
+ /// <summary>
67
+ /// Reads logger settings from the provided configuration object using the default section name. Generally this
68
+ /// is preferable over the other method that takes a configuration section. Only this version will populate
69
+ /// IConfiguration parameters on target methods.
70
+ /// </summary>
71
+ /// <param name="settingConfiguration">Logger setting configuration.</param>
72
+ /// <param name="configuration">A configuration object which contains a Serilog section.</param>
73
+ /// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
74
+ /// default will be used.</param>
75
+ /// <returns>An object allowing configuration to continue.</returns>
76
+ public static LoggerConfiguration Configuration (
77
+ this LoggerSettingsConfiguration settingConfiguration ,
78
+ IConfiguration configuration ,
79
+ DependencyContext dependencyContext = null )
80
+ => Configuration ( settingConfiguration , configuration , DefaultSectionName , dependencyContext ) ;
81
+
63
82
/// <summary>
64
83
/// Reads logger settings from the provided configuration section. Generally it is preferable to use the other
65
84
/// extension method that takes the full configuration object.
@@ -69,6 +88,7 @@ public static LoggerConfiguration Configuration(
69
88
/// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
70
89
/// default will be used.</param>
71
90
/// <returns>An object allowing configuration to continue.</returns>
91
+ [ Obsolete ( "Use ReadFrom.Configuration(IConfiguration configuration, string sectionName, DependencyContext dependencyContext) instead." ) ]
72
92
public static LoggerConfiguration ConfigurationSection (
73
93
this LoggerSettingsConfiguration settingConfiguration ,
74
94
IConfigurationSection configSection ,
@@ -89,27 +109,45 @@ public static LoggerConfiguration ConfigurationSection(
89
109
}
90
110
91
111
/// <summary>
92
- /// Reads logger settings from the provided configuration object using the default section name. Generally this
112
+ /// Reads logger settings from the provided configuration object using the provided section name. Generally this
93
113
/// is preferable over the other method that takes a configuration section. Only this version will populate
94
114
/// IConfiguration parameters on target methods.
95
115
/// </summary>
96
116
/// <param name="settingConfiguration">Logger setting configuration.</param>
97
117
/// <param name="configuration">A configuration object which contains a Serilog section.</param>
118
+ /// <param name="sectionName">A section name for section which contains a Serilog section.</param>
98
119
/// <param name="configurationAssemblySource">Defines how the package identifies assemblies to scan for sinks and other Types.</param>
99
120
/// <returns>An object allowing configuration to continue.</returns>
100
121
public static LoggerConfiguration Configuration (
101
122
this LoggerSettingsConfiguration settingConfiguration ,
102
123
IConfiguration configuration ,
124
+ string sectionName ,
103
125
ConfigurationAssemblySource configurationAssemblySource )
104
126
{
105
127
if ( settingConfiguration == null ) throw new ArgumentNullException ( nameof ( settingConfiguration ) ) ;
106
128
if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
129
+ if ( sectionName == null ) throw new ArgumentNullException ( nameof ( sectionName ) ) ;
107
130
108
131
var assemblyFinder = AssemblyFinder . ForSource ( configurationAssemblySource ) ;
109
132
110
- return settingConfiguration . Settings ( new ConfigurationReader ( configuration . GetSection ( DefaultSectionName ) , assemblyFinder , configuration ) ) ;
133
+ return settingConfiguration . Settings ( new ConfigurationReader ( configuration . GetSection ( sectionName ) , assemblyFinder , configuration ) ) ;
111
134
}
112
135
136
+ /// <summary>
137
+ /// Reads logger settings from the provided configuration object using the default section name. Generally this
138
+ /// is preferable over the other method that takes a configuration section. Only this version will populate
139
+ /// IConfiguration parameters on target methods.
140
+ /// </summary>
141
+ /// <param name="settingConfiguration">Logger setting configuration.</param>
142
+ /// <param name="configuration">A configuration object which contains a Serilog section.</param>
143
+ /// <param name="configurationAssemblySource">Defines how the package identifies assemblies to scan for sinks and other Types.</param>
144
+ /// <returns>An object allowing configuration to continue.</returns>
145
+ public static LoggerConfiguration Configuration (
146
+ this LoggerSettingsConfiguration settingConfiguration ,
147
+ IConfiguration configuration ,
148
+ ConfigurationAssemblySource configurationAssemblySource )
149
+ => Configuration ( settingConfiguration , configuration , DefaultSectionName , configurationAssemblySource ) ;
150
+
113
151
/// <summary>
114
152
/// Reads logger settings from the provided configuration section. Generally it is preferable to use the other
115
153
/// extension method that takes the full configuration object.
@@ -118,6 +156,7 @@ public static LoggerConfiguration Configuration(
118
156
/// <param name="configSection">The Serilog configuration section</param>
119
157
/// <param name="configurationAssemblySource">Defines how the package identifies assemblies to scan for sinks and other Types.</param>
120
158
/// <returns>An object allowing configuration to continue.</returns>
159
+ [ Obsolete ( "Use ReadFrom.Configuration(IConfiguration configuration, string sectionName, ConfigurationAssemblySource configurationAssemblySource) instead." ) ]
121
160
public static LoggerConfiguration ConfigurationSection (
122
161
this LoggerSettingsConfiguration settingConfiguration ,
123
162
IConfigurationSection configSection ,
0 commit comments