Class LogCollectorBuilder
- Namespace
- LogAssertions
- Assembly
- LogAssertions.dll
Convenience factory that constructs a Microsoft.Extensions.Logging.Testing.FakeLogCollector together with an ILoggerFactory that writes into it. Replaces the 3-4 lines of boilerplate every test would otherwise need.
public static class LogCollectorBuilder
- Inheritance
-
LogCollectorBuilder
- Inherited Members
Examples
var (factory, collector) = LogCollectorBuilder.Create();
using (factory)
{
var logger = factory.CreateLogger("MyCategory");
logger.LogInformation("hello");
await Assert.That(collector).HasLogged().Containing("hello", StringComparison.Ordinal).Once();
}
Methods
Create(LogLevel)
Creates a new Microsoft.Extensions.Logging.Testing.FakeLogCollector and an ILoggerFactory wired to it. The caller owns both: dispose the factory when the test completes; the collector is GC-managed and has no unmanaged resources.
public static (ILoggerFactory Factory, FakeLogCollector Collector) Create(LogLevel minimumLevel = LogLevel.Trace)
Parameters
Returns
- (ILoggerFactory Factory, FakeLogCollector Collector)
The wired pair:
Factoryfor creating loggers,Collectorfor assertions.