Skip to content

Commit 1ca6202

Browse files
authored
Add some additional logging to ErrorPageMiddlewareWebSite (dotnet#8049)
* Add some additional logging to ErrorPageMiddlewareWebSite DeveloperExceptionMiddleware will log an error if rendering the exception page throws. The test failure in https://github.com/aspnet/AspNetCore-Internal/issues/1730 suggests that we encountered an error like so but do not have anything further to go by. This change adds logging to the test so we could identify possible issues
1 parent d2a4435 commit 1ca6202

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Linq;
46
using System.Net;
57
using System.Net.Http;
68
using System.Net.Http.Headers;
79
using System.Text.Encodings.Web;
810
using System.Threading.Tasks;
9-
using Microsoft.AspNetCore.Mvc.Razor.Internal;
11+
using Microsoft.AspNetCore.Hosting;
12+
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Logging;
14+
using Microsoft.Extensions.Logging.Testing;
1015
using Xunit;
16+
using Xunit.Abstractions;
1117

1218
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
1319
{
1420
/// <summary>
1521
/// Functional test to verify the error reporting of Razor compilation by diagnostic middleware.
1622
/// </summary>
17-
public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>>
23+
public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>>, IDisposable
1824
{
1925
private static readonly string PreserveCompilationContextMessage = HtmlEncoder.Default.Encode(
2026
"One or more compilation references are missing. Ensure that your project is referencing " +
2127
"'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false.");
22-
public ErrorPageTests(MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> fixture)
28+
private readonly AssemblyTestLog _assemblyTestLog;
29+
30+
public ErrorPageTests(
31+
MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> fixture,
32+
ITestOutputHelper testOutputHelper)
2333
{
24-
Client = fixture.CreateDefaultClient();
34+
_assemblyTestLog = AssemblyTestLog.ForAssembly(GetType().Assembly);
35+
36+
var loggerProvider = _assemblyTestLog.CreateLoggerFactory(testOutputHelper, GetType().Name);
37+
38+
var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup<ErrorPageMiddlewareWebSite.Startup>());
39+
Client = factory
40+
.WithWebHostBuilder(builder => builder.ConfigureLogging(l => l.Services.AddSingleton<ILoggerFactory>(loggerProvider)))
41+
.CreateDefaultClient();
2542
}
2643

2744
public HttpClient Client { get; }
@@ -144,5 +161,10 @@ public async void AggregateException_FlattensInnerExceptions()
144161
Assert.Contains(nullReferenceException, content);
145162
Assert.Contains(indexOutOfRangeException, content);
146163
}
164+
165+
public void Dispose()
166+
{
167+
_assemblyTestLog.Dispose();
168+
}
147169
}
148170
}

0 commit comments

Comments
 (0)