From 2162aba757dd2281802d7ccf81f127442864fc75 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Wed, 9 Sep 2026 16:58:48 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Print=20the=20scenario's=20log=20en?= =?UTF-8?q?tries=20when=20an=20acceptance=20test=20fails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test endpoints log only into ScenarioContext.Logs, and nothing printed those, so a failure could not be traced past ServiceControl's own output. The Windows-PostgreSql failure that hung in SendLocal for a minute is the example: the receiver endpoint left no trace at all. TearDown now prints the entries the way NServiceBus core's acceptance tests do. --- .../NServiceBusAcceptanceTest.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ServiceControl.AcceptanceTesting/NServiceBusAcceptanceTest.cs b/src/ServiceControl.AcceptanceTesting/NServiceBusAcceptanceTest.cs index b510e326ec..ab5cdd6804 100644 --- a/src/ServiceControl.AcceptanceTesting/NServiceBusAcceptanceTest.cs +++ b/src/ServiceControl.AcceptanceTesting/NServiceBusAcceptanceTest.cs @@ -6,6 +6,7 @@ using NServiceBus.AcceptanceTesting; using NServiceBus.AcceptanceTesting.Customization; using NUnit.Framework; + using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; /// @@ -49,6 +50,22 @@ public void TearDown() TestContext.Out.WriteLine($@"Context: {string.Join(Environment.NewLine, scenarioContext.GetType().GetProperties().Select(p => $"{p.Name} = {p.GetValue(scenarioContext, null)}"))}"); + + var result = TestExecutionContext.CurrentContext.CurrentResult.ResultState; + + if (result == ResultState.Failure || result == ResultState.Error) + { + // The test endpoints only log here. ServiceControl's own host logs here too, on top of + // the live output it already writes, so its lines appear twice for a failed test. + TestContext.Out.WriteLine(); + TestContext.Out.WriteLine($"Log entries (log level: {scenarioContext.LogLevel}):"); + TestContext.Out.WriteLine("--- Start log entries ---------------------------------------------------"); + foreach (var logEntry in scenarioContext.Logs) + { + TestContext.Out.WriteLine($"{logEntry.Timestamp:T} {logEntry.Level} {logEntry.Endpoint ?? TestContext.CurrentContext.Test.Name}: {logEntry.Message}"); + } + TestContext.Out.WriteLine("--- End log entries -----------------------------------------------------"); + } } } } \ No newline at end of file