22using Microsoft . AspNetCore . Http ;
33using Microsoft . AspNetCore . Routing ;
44using Microsoft . Extensions . DependencyInjection ;
5+ using Microsoft . Extensions . Logging ;
56using Microsoft . Extensions . Options ;
67using System . Collections . Generic ;
78using System . Linq ;
@@ -29,12 +30,17 @@ public bool Match(
2930
3031
3132 string requestFolder = GetStartingSegment ( httpContext . Request . Path ) ;
33+
3234 if ( ! string . IsNullOrWhiteSpace ( requestFolder ) )
3335 {
36+ var logger = httpContext . RequestServices . GetService < ILogger < CultureSegmentRouteConstraint > > ( ) ;
37+
3438 var cultureSettingsAccessor = httpContext . RequestServices . GetService < IOptions < RequestLocalizationOptions > > ( ) ;
3539 var cultureSettings = cultureSettingsAccessor . Value ;
36- var found = cultureSettings . SupportedUICultures . Where ( x => x . Name . Equals ( requestFolder , System . StringComparison . InvariantCultureIgnoreCase )
37- || x . TwoLetterISOLanguageName . Equals ( requestFolder , System . StringComparison . InvariantCultureIgnoreCase ) ) . Any ( ) ;
40+ var found = cultureSettings . SupportedUICultures . Where ( x =>
41+ x . Name . Equals ( requestFolder , System . StringComparison . InvariantCultureIgnoreCase )
42+ || x . TwoLetterISOLanguageName . Equals ( requestFolder , System . StringComparison . InvariantCultureIgnoreCase )
43+ ) . Any ( ) ;
3844
3945 var isDefaultCulture = cultureSettings . DefaultRequestCulture . UICulture . Name . Equals ( requestFolder , System . StringComparison . InvariantCultureIgnoreCase )
4046 || cultureSettings . DefaultRequestCulture . UICulture . TwoLetterISOLanguageName . Equals ( requestFolder , System . StringComparison . InvariantCultureIgnoreCase ) ;
@@ -44,8 +50,12 @@ public bool Match(
4450 //don't match default culture because we don't want the culture segment in the url for the default culture
4551 if ( found && ! isDefaultCulture )
4652 {
53+ logger . LogDebug ( $ "matched culture route constraint for path { httpContext . Request . Path } ") ;
54+
4755 return true ;
4856 }
57+
58+ logger . LogDebug ( $ "did not match culture route constraint for path { httpContext . Request . Path } ") ;
4959 }
5060
5161
0 commit comments