Skip to content

Commit

Permalink
Update TestHostBase.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Sep 7, 2023
1 parent 59a0c79 commit 9bedc3b
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/XUnit.Hosting/TestHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,15 @@ protected TestHostBase(ITestOutputHelper output, TFixture ficture)
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
WriteLogs();
}
public void Dispose() => WriteLogs();


/// <summary>
/// Writes the queued logs to <see cref="Output"/>.
/// </summary>
protected void WriteLogs()
{
// find memory logger
var loggers = Services.GetServices<ILoggerProvider>();
var memoryLogger = loggers
.OfType<MemoryLoggerProvider>()
.FirstOrDefault();

var memoryLogger = GetMemoryLogger();
if (memoryLogger == null)
return;

Expand All @@ -83,4 +75,33 @@ protected void WriteLogs()
// reset logger
memoryLogger.Clear();
}

/// <summary>
/// Gets the memory log entries.
/// </summary>
/// <returns>A readonly list of log entries</returns>
protected IReadOnlyList<MemoryLogEntry> GetLogEntries()
{
var memoryLogger = GetMemoryLogger();
if (memoryLogger == null)
return Array.Empty<MemoryLogEntry>();

return memoryLogger.GetEntries();
}

/// <summary>
/// Gets the memory logging provider.
/// </summary>
/// <returns></returns>
protected MemoryLoggerProvider? GetMemoryLogger()
{
// find memory logger
var loggers = Services.GetServices<ILoggerProvider>();
if (loggers == null)
return null;

return loggers
.OfType<MemoryLoggerProvider>()
.FirstOrDefault();
}
}

0 comments on commit 9bedc3b

Please sign in to comment.