Scenario
I call an external service using an access token, which needs to be provided as an query parameter called token
.
Logging output
When doing a GET request from C#, I see this logging (the real token is replaced by eyJ0...
in this example):
[17:53:07 INF] Start processing HTTP request GET https://example.com/auth?token=eyJ0...
[17:53:07 INF] Sending HTTP request GET https://example.com/auth?token=eyJ0...
[17:53:07 INF] Received HTTP response headers after 140.3618ms - 200
[17:53:07 INF] End processing HTTP request after 142.3193ms - 200
Change logging ?
Is there a a easy way using a mandatory custom Logging handler for the HttpClient/HttpClientfactory in such a way that the token
query parameter is replaced by ***
?
Like:
[17:53:07 INF] Start processing HTTP request GET https://example.com/auth?token=***
Note 1:
This code is inside a library, so changing the log-level for the HttpClient/HttpClientfactory in the appsettings.json is not an option. It needs to be secure.
Note 2:
I register the HttpClient / RestEase as follows:
services
.AddTransient<IMyClient, MyClient>()
.AddHttpClient(options.HttpClientName, c => c.BaseAddress = options.ConnectUrl)
.AddPolicyHandler((serviceProvider, request) => HttpClientRetryPolicies.GetPolicy(serviceProvider))
.UseWithRestEaseClient<IMyApi>()
;