mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Concurrent;
|
|
using Microsoft.Extensions.Logging;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Microsoft.Agents.AI.DurableTask.IntegrationTests.Logging;
|
|
|
|
internal sealed class TestLoggerProvider(ITestOutputHelper output) : ILoggerProvider
|
|
{
|
|
private readonly ITestOutputHelper _output = output ?? throw new ArgumentNullException(nameof(output));
|
|
private readonly ConcurrentDictionary<string, TestLogger> _loggers = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
public bool TryGetLogs(string category, out IReadOnlyCollection<LogEntry> logs)
|
|
{
|
|
if (this._loggers.TryGetValue(category, out TestLogger? logger))
|
|
{
|
|
logs = logger.GetLogs();
|
|
return true;
|
|
}
|
|
|
|
logs = [];
|
|
return false;
|
|
}
|
|
|
|
public IReadOnlyCollection<LogEntry> GetAllLogs()
|
|
{
|
|
return this._loggers.Values
|
|
.OfType<TestLogger>()
|
|
.SelectMany(logger => logger.GetLogs())
|
|
.ToList()
|
|
.AsReadOnly();
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
foreach (TestLogger logger in this._loggers.Values.OfType<TestLogger>())
|
|
{
|
|
logger.ClearLogs();
|
|
}
|
|
}
|
|
|
|
ILogger ILoggerProvider.CreateLogger(string categoryName)
|
|
{
|
|
return this._loggers.GetOrAdd(categoryName, _ => new TestLogger(categoryName, this._output));
|
|
}
|
|
|
|
void IDisposable.Dispose()
|
|
{
|
|
// no-op
|
|
}
|
|
}
|