Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace StellaOps.Concelier.Merge.Tests;
|
|
|
|
internal sealed class TestLogger<T> : ILogger<T>
|
|
{
|
|
private static readonly IDisposable NoopScope = new DisposableScope();
|
|
|
|
public List<LogEntry> Entries { get; } = new();
|
|
|
|
public IDisposable BeginScope<TState>(TState state)
|
|
where TState : notnull
|
|
=> NoopScope;
|
|
|
|
public bool IsEnabled(LogLevel logLevel) => true;
|
|
|
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
|
{
|
|
if (formatter is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(formatter));
|
|
}
|
|
|
|
IReadOnlyList<KeyValuePair<string, object?>>? structuredState = null;
|
|
if (state is IReadOnlyList<KeyValuePair<string, object?>> list)
|
|
{
|
|
structuredState = list.ToArray();
|
|
}
|
|
else if (state is IEnumerable<KeyValuePair<string, object?>> enumerable)
|
|
{
|
|
structuredState = enumerable.ToArray();
|
|
}
|
|
|
|
Entries.Add(new LogEntry(logLevel, eventId, formatter(state, exception), structuredState));
|
|
}
|
|
|
|
internal sealed record LogEntry(
|
|
LogLevel Level,
|
|
EventId EventId,
|
|
string Message,
|
|
IReadOnlyList<KeyValuePair<string, object?>>? StructuredState);
|
|
|
|
private sealed class DisposableScope : IDisposable
|
|
{
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
}
|