@@ -47,6 +47,7 @@ public static LoggerConfiguration Configuration(
47
47
DependencyContext dependencyContext = null )
48
48
{
49
49
if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
50
+
50
51
return settingConfiguration . Settings (
51
52
new ConfigurationReader (
52
53
configuration ,
@@ -69,11 +70,63 @@ public static LoggerConfiguration ConfigurationSection(
69
70
{
70
71
if ( settingConfiguration == null ) throw new ArgumentNullException ( nameof ( settingConfiguration ) ) ;
71
72
if ( configSection == null ) throw new ArgumentNullException ( nameof ( configSection ) ) ;
72
-
73
+
73
74
return settingConfiguration . Settings (
74
75
new ConfigurationReader (
75
76
configSection ,
76
77
dependencyContext ?? ( Assembly . GetEntryAssembly ( ) != null ? DependencyContext . Default : null ) ) ) ;
77
78
}
79
+
80
+ /// <summary>
81
+ /// Reads logger settings from the provided configuration object using the default section name. Generally this
82
+ /// is preferable over the other method that takes a configuration section. Only this version will populate
83
+ /// IConfiguration parameters on target methods.
84
+ /// </summary>
85
+ /// <param name="settingConfiguration">Logger setting configuration.</param>
86
+ /// <param name="configuration">A configuration object which contains a Serilog section.</param>
87
+ /// <param name="configurationAssemblySource">Defines how the package identifies assemblies to scan for sinks and other Types.</param>
88
+ /// <returns>An object allowing configuration to continue.</returns>
89
+ public static LoggerConfiguration Configuration (
90
+ this LoggerSettingsConfiguration settingConfiguration ,
91
+ IConfiguration configuration ,
92
+ ConfigurationAssemblySource configurationAssemblySource )
93
+ {
94
+ if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
95
+
96
+ if ( configurationAssemblySource == ConfigurationAssemblySource . UseLoadedAssemblies )
97
+ {
98
+ return Configuration ( settingConfiguration , configuration ) ;
99
+ }
100
+ else
101
+ {
102
+ return settingConfiguration . Settings ( new ConfigurationReader ( configuration , null ) ) ;
103
+ }
104
+ }
105
+
106
+ /// <summary>
107
+ /// Reads logger settings from the provided configuration section. Generally it is preferable to use the other
108
+ /// extension method that takes the full configuration object.
109
+ /// </summary>
110
+ /// <param name="settingConfiguration">Logger setting configuration.</param>
111
+ /// <param name="configSection">The Serilog configuration section</param>
112
+ /// <param name="configurationAssemblySource">Defines how the package identifies assemblies to scan for sinks and other Types.</param>
113
+ /// <returns>An object allowing configuration to continue.</returns>
114
+ public static LoggerConfiguration ConfigurationSection (
115
+ this LoggerSettingsConfiguration settingConfiguration ,
116
+ IConfigurationSection configSection ,
117
+ ConfigurationAssemblySource configurationAssemblySource )
118
+ {
119
+ if ( settingConfiguration == null ) throw new ArgumentNullException ( nameof ( settingConfiguration ) ) ;
120
+ if ( configSection == null ) throw new ArgumentNullException ( nameof ( configSection ) ) ;
121
+
122
+ if ( configurationAssemblySource == ConfigurationAssemblySource . UseLoadedAssemblies )
123
+ {
124
+ return Configuration ( settingConfiguration , configSection ) ;
125
+ }
126
+ else
127
+ {
128
+ return settingConfiguration . Settings ( new ConfigurationReader ( configSection , null ) ) ;
129
+ }
130
+ }
78
131
}
79
132
}
0 commit comments