@@ -403,7 +403,7 @@ public override void Load()
403403 // Update configuration Data dictionary with any results
404404 if ( env != null )
405405 {
406- LogEnvironmentLocated ( env . Name , string . Join ( ", " , env . Profiles . Select ( p => $ "' { p } '" ) ) , env . Label , env . Version , env . State ) ;
406+ ExpensiveLogEnvironmentLocated ( env ) ;
407407
408408 if ( updateDictionary )
409409 {
@@ -451,6 +451,15 @@ public override void Load()
451451 throw new ConfigServerException ( "Failed fetching remote configuration from server(s)." , error ) ;
452452 }
453453
454+ private void ExpensiveLogEnvironmentLocated ( ConfigEnvironment environment )
455+ {
456+ if ( _logger . IsEnabled ( LogLevel . Debug ) )
457+ {
458+ string profiles = string . Join ( ", " , environment . Profiles . Select ( profile => $ "'{ profile } '") ) ;
459+ LogEnvironmentLocated ( environment . Name , profiles , environment . Label , environment . Version , environment . State ) ;
460+ }
461+ }
462+
454463 internal void ApplyLastDiscoveryLookupResultToClientOptions ( ConfigServerClientOptions optionsSnapshot )
455464 {
456465 DiscoveryLookupResult ? lastResult = _lastDiscoveryLookupResult ;
@@ -601,7 +610,7 @@ internal async Task<HttpRequestMessage> GetConfigServerRequestMessageAsync(Confi
601610
602611 if ( requestUri . TryGetUsernamePassword ( out string ? username , out string ? password ) && password . Length > 0 )
603612 {
604- LogAddingCredentials ( requestUri . ToMaskedString ( ) ) ;
613+ LogAddingCredentials ( requestUri ) ;
605614
606615 requestMessage . Headers . Authorization =
607616 new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( $ "{ username } :{ password } ") ) ) ;
@@ -616,7 +625,7 @@ internal async Task<HttpRequestMessage> GetConfigServerRequestMessageAsync(Confi
616625 string accessToken =
617626 await httpClient . GetAccessTokenAsync ( accessTokenUri , optionsSnapshot . ClientId , optionsSnapshot . ClientSecret , cancellationToken ) ;
618627
619- LogAccessTokenFetched ( accessTokenUri . ToMaskedString ( ) ) ;
628+ LogAccessTokenFetched ( accessTokenUri ) ;
620629 requestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
621630 }
622631 }
@@ -646,7 +655,7 @@ internal async Task<HttpRequestMessage> GetConfigServerRequestMessageAsync(Confi
646655 // Make Config Server URI from settings
647656 Uri uri = BuildConfigServerUri ( optionsSnapshot , requestUri , label ) ;
648657
649- LogTryingToConnect ( uri . ToMaskedString ( ) ) ;
658+ LogTryingToConnect ( uri ) ;
650659 HttpRequestMessage request ;
651660
652661 try
@@ -660,7 +669,7 @@ internal async Task<HttpRequestMessage> GetConfigServerRequestMessageAsync(Confi
660669 if ( ! string . IsNullOrEmpty ( optionsSnapshot . AccessTokenUri ) )
661670 {
662671 var accessTokenUri = new Uri ( optionsSnapshot . AccessTokenUri ) ;
663- LogFailedToFetchAccessToken ( exception , accessTokenUri . ToMaskedString ( ) ) ;
672+ LogFailedToFetchAccessToken ( exception , accessTokenUri ) ;
664673
665674 continue ;
666675 }
@@ -672,7 +681,7 @@ internal async Task<HttpRequestMessage> GetConfigServerRequestMessageAsync(Confi
672681 LogSendingHttpRequest ( ) ;
673682 using HttpResponseMessage response = await httpClient . SendAsync ( request , cancellationToken ) ;
674683
675- LogConfigServerReturnedStatus ( response . StatusCode , uri . ToMaskedString ( ) ) ;
684+ LogConfigServerReturnedStatus ( uri , response . StatusCode ) ;
676685
677686 if ( response . StatusCode != HttpStatusCode . OK )
678687 {
@@ -684,7 +693,8 @@ internal async Task<HttpRequestMessage> GetConfigServerRequestMessageAsync(Confi
684693 // Throw if status >= 400
685694 if ( response . StatusCode >= HttpStatusCode . BadRequest )
686695 {
687- throw new HttpRequestException ( $ "Config Server returned status: { response . StatusCode } invoking path: { uri . ToMaskedString ( ) } ") ;
696+ MaskedUri masked = uri ;
697+ throw new HttpRequestException ( $ "Config Server returned status: { response . StatusCode } invoking path: { masked } ") ;
688698 }
689699
690700 return null ;
@@ -827,7 +837,7 @@ internal async Task RefreshVaultTokenAsync(ConfigServerClientOptions optionsSnap
827837 Uri uri = BuildVaultRenewUri ( optionsSnapshot ) ;
828838 HttpRequestMessage message = await GetVaultRenewRequestMessageAsync ( optionsSnapshot , uri , cancellationToken ) ;
829839
830- LogRenewingVaultToken ( obscuredToken , optionsSnapshot . TokenTtl , uri . ToMaskedString ( ) ) ;
840+ LogRenewingVaultToken ( obscuredToken , optionsSnapshot . TokenTtl , uri ) ;
831841 using HttpResponseMessage response = await httpClient . SendAsync ( message , cancellationToken ) ;
832842
833843 if ( response . StatusCode != HttpStatusCode . OK )
@@ -867,7 +877,7 @@ private async Task<HttpRequestMessage> GetVaultRenewRequestMessageAsync(ConfigSe
867877 string accessToken =
868878 await httpClient . GetAccessTokenAsync ( accessTokenUri , optionsSnapshot . ClientId , optionsSnapshot . ClientSecret , cancellationToken ) ;
869879
870- LogAccessTokenFetched ( accessTokenUri . ToMaskedString ( ) ) ;
880+ LogAccessTokenFetched ( accessTokenUri ) ;
871881 requestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
872882 }
873883
@@ -1019,7 +1029,7 @@ private void ShutdownTimers()
10191029 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Multiple Config Server uris listed." ) ]
10201030 private partial void LogMultipleConfigServerUris ( ) ;
10211031
1022- [ LoggerMessage ( Level = LogLevel . Debug ,
1032+ [ LoggerMessage ( Level = LogLevel . Debug , SkipEnabledCheck = true ,
10231033 Message = "Located environment with name {Name}, profiles {Profiles}, label {Label}, version {Version} and state {State}." ) ]
10241034 private partial void LogEnvironmentLocated ( string ? name , string profiles , string ? label , string ? version , string ? state ) ;
10251035
@@ -1030,22 +1040,22 @@ private void ShutdownTimers()
10301040 private partial void LogDataNotChanged ( ) ;
10311041
10321042 [ LoggerMessage ( Level = LogLevel . Warning , Message = "Failed fetching remote configuration from server(s)." ) ]
1033- private partial void LogFetchingRemoteConfigurationFailed ( Exception ? error ) ;
1043+ private partial void LogFetchingRemoteConfigurationFailed ( Exception error ) ;
10341044
10351045 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Adding credentials from '{RequestUri}' to Authorization header." ) ]
1036- private partial void LogAddingCredentials ( string requestUri ) ;
1046+ private partial void LogAddingCredentials ( MaskedUri requestUri ) ;
10371047
10381048 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Fetched access token from {AccessTokenUri}." ) ]
1039- private partial void LogAccessTokenFetched ( string accessTokenUri ) ;
1049+ private partial void LogAccessTokenFetched ( MaskedUri accessTokenUri ) ;
10401050
10411051 [ LoggerMessage ( Level = LogLevel . Warning , Message = "Failed to fetch access token from '{AccessTokenUri}'." ) ]
1042- private partial void LogFailedToFetchAccessToken ( Exception exception , string accessTokenUri ) ;
1052+ private partial void LogFailedToFetchAccessToken ( Exception exception , MaskedUri accessTokenUri ) ;
10431053
10441054 [ LoggerMessage ( Level = LogLevel . Trace , Message = "Entered {Method}." ) ]
10451055 private partial void LogRemoteLoadEntered ( string method ) ;
10461056
10471057 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Trying to connect to Config Server at {RequestUri}." ) ]
1048- private partial void LogTryingToConnect ( string requestUri ) ;
1058+ private partial void LogTryingToConnect ( MaskedUri requestUri ) ;
10491059
10501060 [ LoggerMessage ( Level = LogLevel . Trace , Message = "Building HTTP request message." ) ]
10511061 private partial void LogBuildingHttpRequest ( ) ;
@@ -1054,7 +1064,7 @@ private void ShutdownTimers()
10541064 private partial void LogSendingHttpRequest ( ) ;
10551065
10561066 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Config Server returned status {StatusCode} for path {RequestUri}." ) ]
1057- private partial void LogConfigServerReturnedStatus ( HttpStatusCode statusCode , string requestUri ) ;
1067+ private partial void LogConfigServerReturnedStatus ( MaskedUri requestUri , HttpStatusCode statusCode ) ;
10581068
10591069 [ LoggerMessage ( Level = LogLevel . Trace , Message = "Parsing JSON response." ) ]
10601070 private partial void LogParsingJsonResponse ( ) ;
@@ -1066,7 +1076,7 @@ private void ShutdownTimers()
10661076 private partial void LogConfigServerPropertyException ( Exception exception , string key , Type type ) ;
10671077
10681078 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Renewing Vault token {Token} for {Ttl} milliseconds at Uri {Uri}." ) ]
1069- private partial void LogRenewingVaultToken ( string token , int ttl , string uri ) ;
1079+ private partial void LogRenewingVaultToken ( string token , int ttl , MaskedUri uri ) ;
10701080
10711081 [ LoggerMessage ( Level = LogLevel . Warning , Message = "Renewing Vault token {Token} returned status {Status}." ) ]
10721082 private partial void LogVaultTokenRenewalStatus ( string token , HttpStatusCode status ) ;
0 commit comments