diff --git a/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs b/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs index a7a657354619..d04b68af5dc0 100644 --- a/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs @@ -1,11 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; using Xunit; +using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests { @@ -14,7 +16,11 @@ public class StrictTestServerTests: LoggedTest public override void Dispose() { base.Dispose(); - Assert.DoesNotContain(TestSink.Writes, w => w.LogLevel > LogLevel.Information); + + if (TestSink.Writes.FirstOrDefault(w => w.LogLevel > LogLevel.Information) is WriteContext writeContext) + { + throw new XunitException($"Unexpected log: {writeContext}"); + } } protected static TaskCompletionSource CreateTaskCompletionSource() diff --git a/src/Testing/src/Logging/WriteContext.cs b/src/Testing/src/Logging/WriteContext.cs index 0ecfc8f1a9a7..1f4ad768ba34 100644 --- a/src/Testing/src/Logging/WriteContext.cs +++ b/src/Testing/src/Logging/WriteContext.cs @@ -29,5 +29,10 @@ public string Message return Formatter(State, Exception); } } + + public override string ToString() + { + return $"{LogLevel} {LoggerName}: {Message}"; + } } -} \ No newline at end of file +}