Class TestLogCollector

Namespace
XBullet.EasyTesting.Observability
Assembly
XBullet.EasyTesting.Observability.dll

Thread-safe provider that captures structured application logs in memory.

public sealed class TestLogCollector : ILoggerProvider, IDisposable, ISupportExternalScope, ITestScenarioResource
Inheritance
TestLogCollector
Implements
Inherited Members

Constructors

TestLogCollector(TimeProvider?, int)

Creates a collector with an optional clock and bounded entry count.

public TestLogCollector(TimeProvider? timeProvider = null, int maximumEntries = 1000)

Parameters

timeProvider TimeProvider

The clock used for capture timestamps, or null to use System. The provider is retained but not owned or disposed.

maximumEntries int

The positive maximum number of entries retained. The default is 1,000; when the bound is exceeded, the oldest entries are discarded first.

Properties

Count

Gets the number of currently captured entries.

public int Count { get; }

Property Value

int

A value from zero through the configured maximum entry count.

Entries

Gets a stable copy of captured entries in recording order.

public IReadOnlyList<TestLogEntry> Entries { get; }

Property Value

IReadOnlyList<TestLogEntry>

A newly allocated snapshot in recording order. The caller may retain the list. Entries can contain unredacted messages, state, scopes, and exceptions with sensitive data.

Methods

CaptureDiagnosticsAsync(CancellationToken)

Captures the current state before a failed scenario is cleaned up.

public ValueTask<object?> CaptureDiagnosticsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancels diagnostic collection for this resource. The default token does not request cancellation. A thrown exception, including cancellation, is recorded as a diagnostic capture failure so cleanup can continue.

Returns

ValueTask<object>

A serializable diagnostic value, or null when the resource has no state to report. Ownership remains with the resource unless its implementation states otherwise.

CreateLogger(string)

Creates a new ILogger instance.

public ILogger CreateLogger(string categoryName)

Parameters

categoryName string

The category name for messages produced by the logger.

Returns

ILogger

The instance of ILogger that was created.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Reset()

Removes every captured log entry and returns this collector.

public TestLogCollector Reset()

Returns

TestLogCollector

This collector, for chaining. Its clock, scope provider, and maximum remain unchanged.

ResetAsync(CancellationToken)

Clears mutable state before and after a scenario.

public ValueTask ResetAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancels this reset attempt. The default token does not request cancellation. The factory continues resetting the remaining registered resources and reports all reset failures together.

Returns

ValueTask

A task that completes when the resource has finished resetting its state.

SetScopeProvider(IExternalScopeProvider)

Sets external scope information source for logger provider.

public void SetScopeProvider(IExternalScopeProvider scopeProvider)

Parameters

scopeProvider IExternalScopeProvider

The provider of scope data.

Should()

Starts a fluent assertion chain over the captured logs.

public TestLogCollectorAssertions Should()

Returns

TestLogCollectorAssertions

A new assertion object that reads this collector's current snapshots.