11
11
using Serilog . Core ;
12
12
using Serilog . Debugging ;
13
13
using Serilog . Events ;
14
- using System . Linq . Expressions ;
15
14
using System . Text . RegularExpressions ;
16
15
17
16
namespace Serilog . Settings . Configuration
@@ -354,7 +353,7 @@ internal static IList<MethodInfo> FindSinkConfigurationMethods(IReadOnlyCollecti
354
353
{
355
354
var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerSinkConfiguration ) ) ;
356
355
if ( configurationAssemblies . Contains ( typeof ( LoggerSinkConfiguration ) . GetTypeInfo ( ) . Assembly ) )
357
- found . Add ( GetSurrogateConfigurationMethod < LoggerSinkConfiguration , Action < LoggerConfiguration > , LoggingLevelSwitch > ( ( c , a , s ) => Logger ( c , a , LevelAlias . Minimum , s ) ) ) ;
356
+ found . AddRange ( SurrogateConfigurationMethods . WriteTo ) ;
358
357
359
358
return found ;
360
359
}
@@ -370,7 +369,7 @@ internal static IList<MethodInfo> FindFilterConfigurationMethods(IReadOnlyCollec
370
369
{
371
370
var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerFilterConfiguration ) ) ;
372
371
if ( configurationAssemblies . Contains ( typeof ( LoggerFilterConfiguration ) . GetTypeInfo ( ) . Assembly ) )
373
- found . Add ( GetSurrogateConfigurationMethod < LoggerFilterConfiguration , ILogEventFilter , object > ( ( c , f , _ ) => With ( c , f ) ) ) ;
372
+ found . AddRange ( SurrogateConfigurationMethods . Filter ) ;
374
373
375
374
return found ;
376
375
}
@@ -379,13 +378,7 @@ internal static IList<MethodInfo> FindDestructureConfigurationMethods(IReadOnlyC
379
378
{
380
379
var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerDestructuringConfiguration ) ) ;
381
380
if ( configurationAssemblies . Contains ( typeof ( LoggerDestructuringConfiguration ) . GetTypeInfo ( ) . Assembly ) )
382
- {
383
- found . Add ( GetSurrogateConfigurationMethod < LoggerDestructuringConfiguration , IDestructuringPolicy , object > ( ( c , d , _ ) => With ( c , d ) ) ) ;
384
- found . Add ( GetSurrogateConfigurationMethod < LoggerDestructuringConfiguration , int , object > ( ( c , m , _ ) => ToMaximumDepth ( c , m ) ) ) ;
385
- found . Add ( GetSurrogateConfigurationMethod < LoggerDestructuringConfiguration , int , object > ( ( c , m , _ ) => ToMaximumStringLength ( c , m ) ) ) ;
386
- found . Add ( GetSurrogateConfigurationMethod < LoggerDestructuringConfiguration , int , object > ( ( c , m , _ ) => ToMaximumCollectionCount ( c , m ) ) ) ;
387
- found . Add ( GetSurrogateConfigurationMethod < LoggerDestructuringConfiguration , Type , object > ( ( c , t , _ ) => AsScalar ( c , t ) ) ) ;
388
- }
381
+ found . AddRange ( SurrogateConfigurationMethods . Destructure ) ;
389
382
390
383
return found ;
391
384
}
@@ -394,12 +387,12 @@ internal static IList<MethodInfo> FindEventEnricherConfigurationMethods(IReadOnl
394
387
{
395
388
var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerEnrichmentConfiguration ) ) ;
396
389
if ( configurationAssemblies . Contains ( typeof ( LoggerEnrichmentConfiguration ) . GetTypeInfo ( ) . Assembly ) )
397
- found . Add ( GetSurrogateConfigurationMethod < LoggerEnrichmentConfiguration , object , object > ( ( c , _ , __ ) => FromLogContext ( c ) ) ) ;
390
+ found . AddRange ( SurrogateConfigurationMethods . Enrich ) ;
398
391
399
392
return found ;
400
393
}
401
394
402
- internal static IList < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
395
+ internal static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
403
396
{
404
397
return configurationAssemblies
405
398
. SelectMany ( a => a . ExportedTypes
@@ -411,48 +404,6 @@ internal static IList<MethodInfo> FindConfigurationExtensionMethods(IReadOnlyCol
411
404
. ToList ( ) ;
412
405
}
413
406
414
- /*
415
- Pass-through calls to various Serilog config methods which are
416
- implemented as instance methods rather than extension methods. The
417
- FindXXXConfigurationMethods calls (above) use these to add method
418
- invocation expressions as surrogates so that SelectConfigurationMethod
419
- has a way to match and invoke these instance methods.
420
- */
421
-
422
- // TODO: add overload for array argument (ILogEventEnricher[])
423
- internal static LoggerConfiguration With ( LoggerFilterConfiguration loggerFilterConfiguration , ILogEventFilter filter )
424
- => loggerFilterConfiguration . With ( filter ) ;
425
-
426
- // TODO: add overload for array argument (IDestructuringPolicy[])
427
- internal static LoggerConfiguration With ( LoggerDestructuringConfiguration loggerDestructuringConfiguration , IDestructuringPolicy policy )
428
- => loggerDestructuringConfiguration . With ( policy ) ;
429
-
430
- internal static LoggerConfiguration ToMaximumDepth ( LoggerDestructuringConfiguration loggerDestructuringConfiguration , int maximumDestructuringDepth )
431
- => loggerDestructuringConfiguration . ToMaximumDepth ( maximumDestructuringDepth ) ;
432
-
433
- internal static LoggerConfiguration ToMaximumStringLength ( LoggerDestructuringConfiguration loggerDestructuringConfiguration , int maximumStringLength )
434
- => loggerDestructuringConfiguration . ToMaximumStringLength ( maximumStringLength ) ;
435
-
436
- internal static LoggerConfiguration ToMaximumCollectionCount ( LoggerDestructuringConfiguration loggerDestructuringConfiguration , int maximumCollectionCount )
437
- => loggerDestructuringConfiguration . ToMaximumCollectionCount ( maximumCollectionCount ) ;
438
-
439
- internal static LoggerConfiguration AsScalar ( LoggerDestructuringConfiguration loggerDestructuringConfiguration , Type scalarType )
440
- => loggerDestructuringConfiguration . AsScalar ( scalarType ) ;
441
-
442
- internal static LoggerConfiguration FromLogContext ( LoggerEnrichmentConfiguration loggerEnrichmentConfiguration )
443
- => loggerEnrichmentConfiguration . FromLogContext ( ) ;
444
-
445
- // Unlike the other configuration methods, Logger is an instance method rather than an extension.
446
- internal static LoggerConfiguration Logger (
447
- LoggerSinkConfiguration loggerSinkConfiguration ,
448
- Action < LoggerConfiguration > configureLogger ,
449
- LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
450
- LoggingLevelSwitch levelSwitch = null )
451
- => loggerSinkConfiguration . Logger ( configureLogger , restrictedToMinimumLevel , levelSwitch ) ;
452
-
453
- internal static MethodInfo GetSurrogateConfigurationMethod < TConfiguration , TArg1 , TArg2 > ( Expression < Action < TConfiguration , TArg1 , TArg2 > > method )
454
- => ( method . Body as MethodCallExpression ) ? . Method ;
455
-
456
407
internal static bool IsValidSwitchName ( string input )
457
408
{
458
409
return Regex . IsMatch ( input , LevelSwitchNameRegex ) ;
0 commit comments