1111using Microsoft . AspNetCore . Http . Features ;
1212using Microsoft . AspNetCore . Testing ;
1313using Microsoft . Extensions . DependencyInjection ;
14+ using Microsoft . Extensions . Logging ;
1415using Microsoft . Extensions . Logging . Abstractions ;
1516using Microsoft . Extensions . Metrics ;
1617using Moq ;
1718using static Microsoft . AspNetCore . Hosting . HostingApplication ;
1819
1920namespace Microsoft . AspNetCore . Hosting . Tests ;
2021
21- public class HostingApplicationTests
22+ public class HostingApplicationTests : LoggedTest
2223{
2324 [ Fact ]
2425 public void Metrics ( )
@@ -213,9 +214,11 @@ public void CreateContextCreatesNewContextIfNotUsingDefaultHttpContextFactory()
213214 hostingApplication . DisposeContext ( context , null ) ;
214215 }
215216
216- [ Fact ]
217+ [ Theory ]
218+ [ InlineData ( true ) ]
219+ [ InlineData ( false ) ]
217220 [ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/35142" ) ]
218- public void IHttpActivityFeatureIsPopulated ( )
221+ public void IHttpActivityFeatureIsPopulated ( bool enableLogging )
219222 {
220223 var testSource = new ActivitySource ( Path . GetRandomFileName ( ) ) ;
221224 var dummySource = new ActivitySource ( Path . GetRandomFileName ( ) ) ;
@@ -227,7 +230,8 @@ public void IHttpActivityFeatureIsPopulated()
227230 } ;
228231 ActivitySource . AddActivityListener ( listener ) ;
229232
230- var hostingApplication = CreateApplication ( activitySource : testSource ) ;
233+ var loggerFactory = enableLogging ? LoggerFactory : NullLoggerFactory . Instance ;
234+ var hostingApplication = CreateApplication ( activitySource : testSource , loggerFactory : loggerFactory ) ;
231235 var httpContext = new DefaultHttpContext ( ) ;
232236 var context = hostingApplication . CreateContext ( httpContext . Features ) ;
233237
@@ -289,7 +293,7 @@ public void IHttpActivityFeatureNotUsedFromFeatureCollection()
289293 [ Fact ]
290294 public void IHttpActivityFeatureIsNotPopulatedWithoutAListener ( )
291295 {
292- var hostingApplication = CreateApplication ( ) ;
296+ var hostingApplication = CreateApplication ( loggerFactory : NullLoggerFactory . Instance ) ;
293297 var httpContext = new DefaultHttpContext ( ) ;
294298 httpContext . Features . Set < IHttpActivityFeature > ( new TestHttpActivityFeature ( ) ) ;
295299 var context = hostingApplication . CreateContext ( httpContext . Features ) ;
@@ -302,8 +306,8 @@ public void IHttpActivityFeatureIsNotPopulatedWithoutAListener()
302306 hostingApplication . DisposeContext ( context , null ) ;
303307 }
304308
305- private static HostingApplication CreateApplication ( IHttpContextFactory httpContextFactory = null , bool useHttpContextAccessor = false ,
306- ActivitySource activitySource = null , IMeterFactory meterFactory = null )
309+ private HostingApplication CreateApplication ( IHttpContextFactory httpContextFactory = null , bool useHttpContextAccessor = false ,
310+ ActivitySource activitySource = null , IMeterFactory meterFactory = null , ILoggerFactory loggerFactory = null )
307311 {
308312 var services = new ServiceCollection ( ) ;
309313 services . AddOptions ( ) ;
@@ -313,10 +317,11 @@ private static HostingApplication CreateApplication(IHttpContextFactory httpCont
313317 }
314318
315319 httpContextFactory ??= new DefaultHttpContextFactory ( services . BuildServiceProvider ( ) ) ;
320+ loggerFactory ??= LoggerFactory ;
316321
317322 var hostingApplication = new HostingApplication (
318323 ctx => Task . CompletedTask ,
319- NullLogger . Instance ,
324+ loggerFactory . CreateLogger ( "Microsoft.AspNetCore.Hosting.Diagnostics" ) ,
320325 new DiagnosticListener ( "Microsoft.AspNetCore" ) ,
321326 activitySource ?? new ActivitySource ( "Microsoft.AspNetCore" ) ,
322327 DistributedContextPropagator . CreateDefaultPropagator ( ) ,
0 commit comments