Skip to content

Commit 0454ad9

Browse files
committed
Merge branch 'features/net21rc1' of https://github.com/dotnet/eShopOnContainers into features/net21rc1
2 parents 70a2682 + 6127457 commit 0454ad9

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

src/Web/WebMVC/Startup.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public Startup(IConfiguration configuration)
3636
public void ConfigureServices(IServiceCollection services)
3737
{
3838
services.AddAppInsight(Configuration)
39-
.AddHealthChecks(Configuration)
40-
.AddCustomMvc(Configuration)
41-
.AddHttpClientServices(Configuration)
42-
.AddCustomAuthentication(Configuration);
39+
.AddHealthChecks(Configuration)
40+
.AddCustomMvc(Configuration)
41+
.AddHttpClientServices(Configuration)
42+
//.AddHttpClientLogging(Configuration) //Opt-in HttpClientLogging config
43+
.AddCustomAuthentication(Configuration);
4344
}
4445

4546
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -183,8 +184,11 @@ public static IServiceCollection AddHttpClientServices(this IServiceCollection s
183184
services.AddTransient<HttpClientAuthorizationDelegatingHandler>();
184185
services.AddTransient<HttpClientRequestIdDelegatingHandler>();
185186

186-
//add http client servicse
187+
services.AddHttpClient("extendedhandlerlifetime").SetHandlerLifetime(TimeSpan.FromMinutes(5));
188+
189+
//add http client services
187190
services.AddHttpClient<IBasketService, BasketService>()
191+
.SetHandlerLifetime(TimeSpan.FromMinutes(5)) //Sample. Default lifetime is 2 minutes
188192
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()
189193
.AddPolicyHandler(retriesWithExponentialBackoff)
190194
.AddPolicyHandler(circuitBreaker);
@@ -214,6 +218,23 @@ public static IServiceCollection AddHttpClientServices(this IServiceCollection s
214218

215219
return services;
216220
}
221+
222+
public static IServiceCollection AddHttpClientLogging(this IServiceCollection services, IConfiguration configuration)
223+
{
224+
services.AddLogging(b =>
225+
{
226+
b.AddFilter((category, level) => true); // Spam the world with logs.
227+
228+
// Add console logger so we can see all the logging produced by the client by default.
229+
b.AddConsole(c => c.IncludeScopes = true);
230+
231+
// Add console logger
232+
b.AddDebug();
233+
});
234+
235+
return services;
236+
}
237+
217238
public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration)
218239
{
219240
var useLoadTest = configuration.GetValue<bool>("UseLoadTest");

0 commit comments

Comments
 (0)