/DotNet.Extensions.Logging.Testing

Test and Observable loggers for Microsoft.Extensions.Logging

Primary LanguageC#MIT LicenseMIT

Build status Nuget

DotNet.Extensions.Logging.Testing

Test and Observable loggers for Microsoft.Extensions.Logging.

Usage

Using LogCollector to collect logs produced by a component that depends on ILogger

  var logCollector = new LogCollector();
  
  using(logCollector.CollectLogs())
  {
    ILogger logger = logCollector.Logger;
    
    // code that uses logger instance.
  }
  
  Assert.AreEquals(5, logCollector.Logs);

Using LogCollector to collect logs produced by a component that depends on ILogger<>

  var logCollector = new LogCollector<MyClass>();
  
  using(logCollector.CollectLogs())
  {
    ILogger<MyClass> logger = logCollector.Logger;
    
    // code that uses logger instance.
  }
  
  Assert.AreEquals(5, logCollector.Logs);

Using ObservableLogger to dump logs produced by a component that depends on ILogger

  using (var subject = new Subject<LogEvent>();
  using (var logger = new ObservableLogger("Category", (a,b) => true, subject))
  {
    subject.Dump();
     
    // code that uses logger instance.
  
    Console.ReadLine();
  }