Files
microsoft--agent-framework/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/Logging/TestLoggerProvider.cs
T
wehub-resource-sync db620d33df
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:25 +08:00

52 lines
1.4 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;
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
}
}