1111using Serilog . Core ;
1212using Serilog . Debugging ;
1313using Serilog . Events ;
14- using System . Linq . Expressions ;
1514using System . Text . RegularExpressions ;
1615
1716namespace Serilog . Settings . Configuration
@@ -354,7 +353,7 @@ internal static IList<MethodInfo> FindSinkConfigurationMethods(IReadOnlyCollecti
354353 {
355354 var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerSinkConfiguration ) ) ;
356355 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 ) ;
358357
359358 return found ;
360359 }
@@ -370,7 +369,7 @@ internal static IList<MethodInfo> FindFilterConfigurationMethods(IReadOnlyCollec
370369 {
371370 var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerFilterConfiguration ) ) ;
372371 if ( configurationAssemblies . Contains ( typeof ( LoggerFilterConfiguration ) . GetTypeInfo ( ) . Assembly ) )
373- found . Add ( GetSurrogateConfigurationMethod < LoggerFilterConfiguration , ILogEventFilter , object > ( ( c , f , _ ) => With ( c , f ) ) ) ;
372+ found . AddRange ( SurrogateConfigurationMethods . Filter ) ;
374373
375374 return found ;
376375 }
@@ -379,13 +378,7 @@ internal static IList<MethodInfo> FindDestructureConfigurationMethods(IReadOnlyC
379378 {
380379 var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerDestructuringConfiguration ) ) ;
381380 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 ) ;
389382
390383 return found ;
391384 }
@@ -394,12 +387,12 @@ internal static IList<MethodInfo> FindEventEnricherConfigurationMethods(IReadOnl
394387 {
395388 var found = FindConfigurationExtensionMethods ( configurationAssemblies , typeof ( LoggerEnrichmentConfiguration ) ) ;
396389 if ( configurationAssemblies . Contains ( typeof ( LoggerEnrichmentConfiguration ) . GetTypeInfo ( ) . Assembly ) )
397- found . Add ( GetSurrogateConfigurationMethod < LoggerEnrichmentConfiguration , object , object > ( ( c , _ , __ ) => FromLogContext ( c ) ) ) ;
390+ found . AddRange ( SurrogateConfigurationMethods . Enrich ) ;
398391
399392 return found ;
400393 }
401394
402- internal static IList < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
395+ internal static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
403396 {
404397 return configurationAssemblies
405398 . SelectMany ( a => a . ExportedTypes
@@ -411,48 +404,6 @@ internal static IList<MethodInfo> FindConfigurationExtensionMethods(IReadOnlyCol
411404 . ToList ( ) ;
412405 }
413406
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-
456407 internal static bool IsValidSwitchName ( string input )
457408 {
458409 return Regex . IsMatch ( input , LevelSwitchNameRegex ) ;
0 commit comments