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