InMemoryLogger 1.0.66

Microsoft.Extensions.Logging compatible logger for recording log messages during tests

Install-Package InMemoryLogger -Version 1.0.66
dotnet add package InMemoryLogger --version 1.0.66
<PackageReference Include="InMemoryLogger" Version="1.0.66" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add InMemoryLogger --version 1.0.66
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Build Status
NuGet version

InMemoryLogger

Microsoft.Extensions.Logging compatible logger for recording log messages during tests

Getting started

Install from NuGet:

>  dotnet add package InMemoryLogger 

Then add InMemoryLogger as the logger in your applications service collection:

      var services = new ServiceCollection()
        .AddLogging(x => x.AddInMemory())
        .BuildServiceProvider();

      var inMemLogger = services.GetService<InMemoryLogger>();

And then write a test that asserts on logs messages:

      var logger = services.GetService<ILogger<MyTest>>();
      logger.LogWarning("This is a log message");
      Assert.Contains(inMemLogger.RecordedWarningLogs, l => l.Message == "This is a log message");

Or on logged exceptions:

      var logger = services.GetService<ILogger<MyTest>>();
      var expected = new Exception();
      logger.LogError(expected, "This is another log message");
      Assert.Contains(inMemLogger.RecordedErrorLogs, l => l.Exception == expected);

That's it. All logs are in memory, all logs are recorded.

Build Status
NuGet version

InMemoryLogger

Microsoft.Extensions.Logging compatible logger for recording log messages during tests

Getting started

Install from NuGet:

>  dotnet add package InMemoryLogger 

Then add InMemoryLogger as the logger in your applications service collection:

      var services = new ServiceCollection()
        .AddLogging(x => x.AddInMemory())
        .BuildServiceProvider();

      var inMemLogger = services.GetService<InMemoryLogger>();

And then write a test that asserts on logs messages:

      var logger = services.GetService<ILogger<MyTest>>();
      logger.LogWarning("This is a log message");
      Assert.Contains(inMemLogger.RecordedWarningLogs, l => l.Message == "This is a log message");

Or on logged exceptions:

      var logger = services.GetService<ILogger<MyTest>>();
      var expected = new Exception();
      logger.LogError(expected, "This is another log message");
      Assert.Contains(inMemLogger.RecordedErrorLogs, l => l.Exception == expected);

That's it. All logs are in memory, all logs are recorded.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.66 77 6/18/2019
1.0.58 85 5/26/2019