@@ -233,7 +233,7 @@ void ApplyFilters(LoggerConfiguration loggerConfiguration)
233233 if ( filterDirective . GetChildren ( ) . Any ( ) )
234234 {
235235 var methodCalls = GetMethodCalls ( filterDirective ) ;
236- CallConfigurationMethods ( methodCalls , FindFilterConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . Filter ) ;
236+ CallConfigurationMethods ( methodCalls , FindFilterConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . Filter ) ;
237237 }
238238 }
239239
@@ -243,7 +243,7 @@ void ApplyDestructuring(LoggerConfiguration loggerConfiguration)
243243 if ( destructureDirective . GetChildren ( ) . Any ( ) )
244244 {
245245 var methodCalls = GetMethodCalls ( destructureDirective ) ;
246- CallConfigurationMethods ( methodCalls , FindDestructureConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . Destructure ) ;
246+ CallConfigurationMethods ( methodCalls , FindDestructureConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . Destructure ) ;
247247 }
248248 }
249249
@@ -253,7 +253,7 @@ void ApplySinks(LoggerConfiguration loggerConfiguration)
253253 if ( writeToDirective . GetChildren ( ) . Any ( ) )
254254 {
255255 var methodCalls = GetMethodCalls ( writeToDirective ) ;
256- CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . WriteTo ) ;
256+ CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . WriteTo ) ;
257257 }
258258 }
259259
@@ -263,20 +263,20 @@ void ApplyAuditSinks(LoggerConfiguration loggerConfiguration)
263263 if ( auditToDirective . GetChildren ( ) . Any ( ) )
264264 {
265265 var methodCalls = GetMethodCalls ( auditToDirective ) ;
266- CallConfigurationMethods ( methodCalls , FindAuditSinkConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . AuditTo ) ;
266+ CallConfigurationMethods ( methodCalls , FindAuditSinkConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . AuditTo ) ;
267267 }
268268 }
269269
270270 void IConfigurationReader . ApplySinks ( LoggerSinkConfiguration loggerSinkConfiguration )
271271 {
272272 var methodCalls = GetMethodCalls ( _section ) ;
273- CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies ) , loggerSinkConfiguration ) ;
273+ CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerSinkConfiguration ) ;
274274 }
275275
276276 void IConfigurationReader . ApplyEnrichment ( LoggerEnrichmentConfiguration loggerEnrichmentConfiguration )
277277 {
278278 var methodCalls = GetMethodCalls ( _section ) ;
279- CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies ) , loggerEnrichmentConfiguration ) ;
279+ CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerEnrichmentConfiguration ) ;
280280 }
281281
282282 void ApplyEnrichment ( LoggerConfiguration loggerConfiguration )
@@ -285,7 +285,7 @@ void ApplyEnrichment(LoggerConfiguration loggerConfiguration)
285285 if ( enrichDirective . GetChildren ( ) . Any ( ) )
286286 {
287287 var methodCalls = GetMethodCalls ( enrichDirective ) ;
288- CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . Enrich ) ;
288+ CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . Enrich ) ;
289289 }
290290
291291 var propertiesDirective = _section . GetSection ( "Properties" ) ;
@@ -494,51 +494,51 @@ static bool ParameterNameMatches(string? actualParameterName, IEnumerable<string
494494 return suppliedNames . Any ( s => ParameterNameMatches ( actualParameterName , s ) ) ;
495495 }
496496
497- static IReadOnlyCollection < MethodInfo > FindSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
497+ static IReadOnlyCollection < MethodInfo > FindSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
498498 {
499- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerSinkConfiguration ) ) ;
499+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerSinkConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
500500 if ( configurationAssemblies . Contains ( typeof ( LoggerSinkConfiguration ) . GetTypeInfo ( ) . Assembly ) )
501501 found . AddRange ( SurrogateConfigurationMethods . WriteTo ) ;
502502
503503 return found ;
504504 }
505505
506- static IReadOnlyCollection < MethodInfo > FindAuditSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
506+ static IReadOnlyCollection < MethodInfo > FindAuditSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
507507 {
508- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerAuditSinkConfiguration ) ) ;
508+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerAuditSinkConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
509509 if ( configurationAssemblies . Contains ( typeof ( LoggerAuditSinkConfiguration ) . GetTypeInfo ( ) . Assembly ) )
510510 found . AddRange ( SurrogateConfigurationMethods . AuditTo ) ;
511511 return found ;
512512 }
513513
514- static IReadOnlyCollection < MethodInfo > FindFilterConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
514+ static IReadOnlyCollection < MethodInfo > FindFilterConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
515515 {
516- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerFilterConfiguration ) ) ;
516+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerFilterConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
517517 if ( configurationAssemblies . Contains ( typeof ( LoggerFilterConfiguration ) . GetTypeInfo ( ) . Assembly ) )
518518 found . AddRange ( SurrogateConfigurationMethods . Filter ) ;
519519
520520 return found ;
521521 }
522522
523- static IReadOnlyCollection < MethodInfo > FindDestructureConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
523+ static IReadOnlyCollection < MethodInfo > FindDestructureConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
524524 {
525- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerDestructuringConfiguration ) ) ;
525+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerDestructuringConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
526526 if ( configurationAssemblies . Contains ( typeof ( LoggerDestructuringConfiguration ) . GetTypeInfo ( ) . Assembly ) )
527527 found . AddRange ( SurrogateConfigurationMethods . Destructure ) ;
528528
529529 return found ;
530530 }
531531
532- static IReadOnlyCollection < MethodInfo > FindEventEnricherConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
532+ static IReadOnlyCollection < MethodInfo > FindEventEnricherConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
533533 {
534- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerEnrichmentConfiguration ) ) ;
534+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerEnrichmentConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
535535 if ( configurationAssemblies . Contains ( typeof ( LoggerEnrichmentConfiguration ) . GetTypeInfo ( ) . Assembly ) )
536536 found . AddRange ( SurrogateConfigurationMethods . Enrich ) ;
537537
538538 return found ;
539539 }
540540
541- static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
541+ static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType , bool allowInternalTypes , bool allowInternalMethods )
542542 {
543543 // ExtensionAttribute can be polyfilled to support extension methods
544544 static bool HasCustomExtensionAttribute ( MethodInfo m )
@@ -554,11 +554,11 @@ static bool HasCustomExtensionAttribute(MethodInfo m)
554554 }
555555
556556 return configurationAssemblies
557- . SelectMany ( a => a . ExportedTypes
557+ . SelectMany ( a => ( allowInternalTypes ? a . GetTypes ( ) : a . ExportedTypes )
558558 . Select ( t => t . GetTypeInfo ( ) )
559- . Where ( t => t . IsSealed && t . IsAbstract && ! t . IsNested ) )
559+ . Where ( t => t . IsSealed && t . IsAbstract && ! t . IsNested && ( t . IsPublic || allowInternalTypes && ! t . IsVisible ) ) )
560560 . SelectMany ( t => t . DeclaredMethods )
561- . Where ( m => m . IsStatic && m . IsPublic && ( m . IsDefined ( typeof ( ExtensionAttribute ) , false ) || HasCustomExtensionAttribute ( m ) ) )
561+ . Where ( m => m . IsStatic && ( m . IsPublic || allowInternalMethods && m . IsAssembly ) && ( m . IsDefined ( typeof ( ExtensionAttribute ) , false ) || HasCustomExtensionAttribute ( m ) ) )
562562 . Where ( m => m . GetParameters ( ) [ 0 ] . ParameterType == configType )
563563 . ToList ( ) ;
564564 }
0 commit comments