Files
RobustToolbox/Robust.UnitTesting/LogCatcher.cs
T
AcruidandGitHub 2183cd7ca1 Massive Namespace Cleanup (#1544)
* Removed the Interfaces folder.
* All objects inside the GameObjects subfolders are now in the GameObjects namespace.
* Added a Resharper DotSettings file to mark the GameObjects subfolders as not providing namespaces.
* Simplified Robust.client.Graphics namespace.
* Automated remove redundant using statements.
2021-02-10 23:27:19 -08:00

38 lines
933 B
C#

using System.Collections.Generic;
using Robust.Shared.Log;
using Serilog.Events;
namespace Robust.UnitTesting
{
/// <summary>
/// Utility class for testing that logs are indeed being thrown.
/// </summary>
public class LogCatcher : ILogHandler
{
/// <summary>
/// Read only list of every log message that was caught since the last flush.
/// </summary>
public IReadOnlyList<LogEvent> CaughtLogs => _logs;
private readonly List<LogEvent> _logs = new();
/// <summary>
/// Clears all currently caught logs
/// </summary>
public void Flush()
{
lock (_logs)
{
_logs.Clear();
}
}
void ILogHandler.Log(string sawmillName, LogEvent message)
{
lock (_logs)
{
_logs.Add(message);
}
}
}
}