diff --git a/src/XUnit.Hosting/TestHostBase.cs b/src/XUnit.Hosting/TestHostBase.cs index ee91434..54823f6 100644 --- a/src/XUnit.Hosting/TestHostBase.cs +++ b/src/XUnit.Hosting/TestHostBase.cs @@ -53,10 +53,7 @@ protected TestHostBase(ITestOutputHelper output, TFixture ficture) /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// - public void Dispose() - { - WriteLogs(); - } + public void Dispose() => WriteLogs(); /// @@ -64,12 +61,7 @@ public void Dispose() /// protected void WriteLogs() { - // find memory logger - var loggers = Services.GetServices(); - var memoryLogger = loggers - .OfType() - .FirstOrDefault(); - + var memoryLogger = GetMemoryLogger(); if (memoryLogger == null) return; @@ -83,4 +75,33 @@ protected void WriteLogs() // reset logger memoryLogger.Clear(); } + + /// + /// Gets the memory log entries. + /// + /// A readonly list of log entries + protected IReadOnlyList GetLogEntries() + { + var memoryLogger = GetMemoryLogger(); + if (memoryLogger == null) + return Array.Empty(); + + return memoryLogger.GetEntries(); + } + + /// + /// Gets the memory logging provider. + /// + /// + protected MemoryLoggerProvider? GetMemoryLogger() + { + // find memory logger + var loggers = Services.GetServices(); + if (loggers == null) + return null; + + return loggers + .OfType() + .FirstOrDefault(); + } }