@@ -233,7 +233,7 @@ void ApplyFilters(LoggerConfiguration loggerConfiguration)
233
233
if ( filterDirective . GetChildren ( ) . Any ( ) )
234
234
{
235
235
var methodCalls = GetMethodCalls ( filterDirective ) ;
236
- CallConfigurationMethods ( methodCalls , FindFilterConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . Filter ) ;
236
+ CallConfigurationMethods ( methodCalls , FindFilterConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . Filter ) ;
237
237
}
238
238
}
239
239
@@ -243,7 +243,7 @@ void ApplyDestructuring(LoggerConfiguration loggerConfiguration)
243
243
if ( destructureDirective . GetChildren ( ) . Any ( ) )
244
244
{
245
245
var methodCalls = GetMethodCalls ( destructureDirective ) ;
246
- CallConfigurationMethods ( methodCalls , FindDestructureConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . Destructure ) ;
246
+ CallConfigurationMethods ( methodCalls , FindDestructureConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . Destructure ) ;
247
247
}
248
248
}
249
249
@@ -253,7 +253,7 @@ void ApplySinks(LoggerConfiguration loggerConfiguration)
253
253
if ( writeToDirective . GetChildren ( ) . Any ( ) )
254
254
{
255
255
var methodCalls = GetMethodCalls ( writeToDirective ) ;
256
- CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . WriteTo ) ;
256
+ CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . WriteTo ) ;
257
257
}
258
258
}
259
259
@@ -263,20 +263,20 @@ void ApplyAuditSinks(LoggerConfiguration loggerConfiguration)
263
263
if ( auditToDirective . GetChildren ( ) . Any ( ) )
264
264
{
265
265
var methodCalls = GetMethodCalls ( auditToDirective ) ;
266
- CallConfigurationMethods ( methodCalls , FindAuditSinkConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . AuditTo ) ;
266
+ CallConfigurationMethods ( methodCalls , FindAuditSinkConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . AuditTo ) ;
267
267
}
268
268
}
269
269
270
270
void IConfigurationReader . ApplySinks ( LoggerSinkConfiguration loggerSinkConfiguration )
271
271
{
272
272
var methodCalls = GetMethodCalls ( _section ) ;
273
- CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies ) , loggerSinkConfiguration ) ;
273
+ CallConfigurationMethods ( methodCalls , FindSinkConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerSinkConfiguration ) ;
274
274
}
275
275
276
276
void IConfigurationReader . ApplyEnrichment ( LoggerEnrichmentConfiguration loggerEnrichmentConfiguration )
277
277
{
278
278
var methodCalls = GetMethodCalls ( _section ) ;
279
- CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies ) , loggerEnrichmentConfiguration ) ;
279
+ CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerEnrichmentConfiguration ) ;
280
280
}
281
281
282
282
void ApplyEnrichment ( LoggerConfiguration loggerConfiguration )
@@ -285,7 +285,7 @@ void ApplyEnrichment(LoggerConfiguration loggerConfiguration)
285
285
if ( enrichDirective . GetChildren ( ) . Any ( ) )
286
286
{
287
287
var methodCalls = GetMethodCalls ( enrichDirective ) ;
288
- CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies ) , loggerConfiguration . Enrich ) ;
288
+ CallConfigurationMethods ( methodCalls , FindEventEnricherConfigurationMethods ( _configurationAssemblies , _resolutionContext . ReaderOptions . AllowInternalTypes , _resolutionContext . ReaderOptions . AllowInternalMethods ) , loggerConfiguration . Enrich ) ;
289
289
}
290
290
291
291
var propertiesDirective = _section . GetSection ( "Properties" ) ;
@@ -494,51 +494,51 @@ static bool ParameterNameMatches(string? actualParameterName, IEnumerable<string
494
494
return suppliedNames . Any ( s => ParameterNameMatches ( actualParameterName , s ) ) ;
495
495
}
496
496
497
- static IReadOnlyCollection < MethodInfo > FindSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
497
+ static IReadOnlyCollection < MethodInfo > FindSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
498
498
{
499
- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerSinkConfiguration ) ) ;
499
+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerSinkConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
500
500
if ( configurationAssemblies . Contains ( typeof ( LoggerSinkConfiguration ) . GetTypeInfo ( ) . Assembly ) )
501
501
found . AddRange ( SurrogateConfigurationMethods . WriteTo ) ;
502
502
503
503
return found ;
504
504
}
505
505
506
- static IReadOnlyCollection < MethodInfo > FindAuditSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
506
+ static IReadOnlyCollection < MethodInfo > FindAuditSinkConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
507
507
{
508
- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerAuditSinkConfiguration ) ) ;
508
+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerAuditSinkConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
509
509
if ( configurationAssemblies . Contains ( typeof ( LoggerAuditSinkConfiguration ) . GetTypeInfo ( ) . Assembly ) )
510
510
found . AddRange ( SurrogateConfigurationMethods . AuditTo ) ;
511
511
return found ;
512
512
}
513
513
514
- static IReadOnlyCollection < MethodInfo > FindFilterConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
514
+ static IReadOnlyCollection < MethodInfo > FindFilterConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
515
515
{
516
- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerFilterConfiguration ) ) ;
516
+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerFilterConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
517
517
if ( configurationAssemblies . Contains ( typeof ( LoggerFilterConfiguration ) . GetTypeInfo ( ) . Assembly ) )
518
518
found . AddRange ( SurrogateConfigurationMethods . Filter ) ;
519
519
520
520
return found ;
521
521
}
522
522
523
- static IReadOnlyCollection < MethodInfo > FindDestructureConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
523
+ static IReadOnlyCollection < MethodInfo > FindDestructureConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
524
524
{
525
- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerDestructuringConfiguration ) ) ;
525
+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerDestructuringConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
526
526
if ( configurationAssemblies . Contains ( typeof ( LoggerDestructuringConfiguration ) . GetTypeInfo ( ) . Assembly ) )
527
527
found . AddRange ( SurrogateConfigurationMethods . Destructure ) ;
528
528
529
529
return found ;
530
530
}
531
531
532
- static IReadOnlyCollection < MethodInfo > FindEventEnricherConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies )
532
+ static IReadOnlyCollection < MethodInfo > FindEventEnricherConfigurationMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , bool allowInternalTypes , bool allowInternalMethods )
533
533
{
534
- var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerEnrichmentConfiguration ) ) ;
534
+ var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerEnrichmentConfiguration ) , allowInternalTypes , allowInternalMethods ) ;
535
535
if ( configurationAssemblies . Contains ( typeof ( LoggerEnrichmentConfiguration ) . GetTypeInfo ( ) . Assembly ) )
536
536
found . AddRange ( SurrogateConfigurationMethods . Enrich ) ;
537
537
538
538
return found ;
539
539
}
540
540
541
- static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
541
+ static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType , bool allowInternalTypes , bool allowInternalMethods )
542
542
{
543
543
// ExtensionAttribute can be polyfilled to support extension methods
544
544
static bool HasCustomExtensionAttribute ( MethodInfo m )
@@ -554,11 +554,11 @@ static bool HasCustomExtensionAttribute(MethodInfo m)
554
554
}
555
555
556
556
return configurationAssemblies
557
- . SelectMany ( a => a . ExportedTypes
557
+ . SelectMany ( a => ( allowInternalTypes ? a . GetTypes ( ) : a . ExportedTypes )
558
558
. 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 ) ) )
560
560
. 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 ) ) )
562
562
. Where ( m => m . GetParameters ( ) [ 0 ] . ParameterType == configType )
563
563
. ToList ( ) ;
564
564
}
0 commit comments