2121
2222namespace Serilog
2323{
24+ /// <summary>
25+ /// Defines the interpretation of a null DependencyContext configuration parameter.
26+ /// </summary>
27+ public enum ConfigurationAssemblySource
28+ {
29+ /// <summary>
30+ /// Try to scan the assemblies already in memory. This is the default. If GetEntryAssembly is null, fallback to DLL scanning.
31+ /// </summary>
32+ UseLoadedAssemblies ,
33+
34+ /// <summary>
35+ /// Scan for assemblies in DLLs from the working directory. This is the fallback when GetEntryAssembly is null.
36+ /// </summary>
37+ AlwaysScanDllFiles
38+ }
39+
2440 /// <summary>
2541 /// Extends <see cref="LoggerConfiguration"/> with support for System.Configuration appSettings elements.
2642 /// </summary>
@@ -38,19 +54,23 @@ public static class ConfigurationLoggerConfigurationExtensions
3854 /// </summary>
3955 /// <param name="settingConfiguration">Logger setting configuration.</param>
4056 /// <param name="configuration">A configuration object which contains a Serilog section.</param>
41- /// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
42- /// default will be used.</param>
57+ /// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located.</param>
58+ /// <param name="onNullDependencyContext">If dependency context is not supplied, either the platform default or DLL scanning may be used.</param>
4359 /// <returns>An object allowing configuration to continue.</returns>
4460 public static LoggerConfiguration Configuration (
4561 this LoggerSettingsConfiguration settingConfiguration ,
4662 IConfiguration configuration ,
47- DependencyContext dependencyContext = null )
63+ DependencyContext dependencyContext = null ,
64+ ConfigurationAssemblySource onNullDependencyContext = ConfigurationAssemblySource . UseLoadedAssemblies )
4865 {
4966 if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
5067 return settingConfiguration . Settings (
5168 new ConfigurationReader (
5269 configuration ,
53- dependencyContext ?? ( Assembly . GetEntryAssembly ( ) != null ? DependencyContext . Default : null ) ) ) ;
70+ dependencyContext ??
71+ ( onNullDependencyContext == ConfigurationAssemblySource . UseLoadedAssemblies
72+ && Assembly . GetEntryAssembly ( ) != null
73+ ? DependencyContext . Default : null ) ) ) ;
5474 }
5575
5676 /// <summary>
@@ -59,21 +79,25 @@ public static LoggerConfiguration Configuration(
5979 /// </summary>
6080 /// <param name="settingConfiguration">Logger setting configuration.</param>
6181 /// <param name="configSection">The Serilog configuration section</param>
62- /// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
63- /// default will be used.</param>
82+ /// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located.</param>
83+ /// <param name="onNullDependencyContext">If dependency context is not supplied, either the platform default or DLL scanning may be used.</param>
6484 /// <returns>An object allowing configuration to continue.</returns>
6585 public static LoggerConfiguration ConfigurationSection (
6686 this LoggerSettingsConfiguration settingConfiguration ,
6787 IConfigurationSection configSection ,
68- DependencyContext dependencyContext = null )
88+ DependencyContext dependencyContext = null ,
89+ ConfigurationAssemblySource onNullDependencyContext = ConfigurationAssemblySource . UseLoadedAssemblies )
6990 {
7091 if ( settingConfiguration == null ) throw new ArgumentNullException ( nameof ( settingConfiguration ) ) ;
7192 if ( configSection == null ) throw new ArgumentNullException ( nameof ( configSection ) ) ;
7293
7394 return settingConfiguration . Settings (
7495 new ConfigurationReader (
7596 configSection ,
76- dependencyContext ?? ( Assembly . GetEntryAssembly ( ) != null ? DependencyContext . Default : null ) ) ) ;
97+ dependencyContext ??
98+ ( onNullDependencyContext == ConfigurationAssemblySource . UseLoadedAssemblies
99+ && Assembly . GetEntryAssembly ( ) != null
100+ ? DependencyContext . Default : null ) ) ) ;
77101 }
78102 }
79103}
0 commit comments