Extensions.Logging.Mock
10.0.0
dotnet add package Extensions.Logging.Mock --version 10.0.0
NuGet\Install-Package Extensions.Logging.Mock -Version 10.0.0
<PackageReference Include="Extensions.Logging.Mock" Version="10.0.0" />
<PackageVersion Include="Extensions.Logging.Mock" Version="10.0.0" />
<PackageReference Include="Extensions.Logging.Mock" />
paket add Extensions.Logging.Mock --version 10.0.0
#r "nuget: Extensions.Logging.Mock, 10.0.0"
#:package Extensions.Logging.Mock@10.0.0
#addin nuget:?package=Extensions.Logging.Mock&version=10.0.0
#tool nuget:?package=Extensions.Logging.Mock&version=10.0.0
Extensions.Logging.Mock
A unit-testing extension for verifying a logger mock.
This repository was moved to https://codeberg.org/mgernand/Extensions.Logging.Mock
Configuration
To configure the intrastructure you just have to call AddMock() on the ILoggingBuilder
instance. when using AddLogging(). This will add a custom ILoggerProvider which will
return the underlying instance of the configured Mock<ILogger> instance.
[TestFixture]
public class LoggerTests
{
public Mock<ILogger> MockLogger { get; set; }
public ILogger Logger { get; set; }
public ILogger<TestClass> GenericLogger { get; set; }
[SetUp]
public void SetUp()
{
this.MockLogger = new Mock<ILogger>();
IServiceCollection services = new ServiceCollection();
services.AddLogging(builder =>
{
builder.SetMinimumLevel(LogLevel.Trace);
builder.AddConsole();
builder.AddMock(this.MockLogger);
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
this.Logger = loggerFactory.CreateLogger("TestLogger");
this.GenericLogger = loggerFactory.CreateLogger<TestClass>();
}
}
Usage
To verify that the desired log methods was called just verify the mock instance using
VerifyLog().DebugWasCalled().
[Test]
public void ShouldVerifyDebugCalled()
{
this.Logger.LogDebug("Log Message");
this.MockLogger.VerifyLog().DebugWasCalled();
}
To verify that the desired log methods message output equals a desired values just verify
the mock instance using VerifyLog().DebugWasCalled().MessageEquals("Log Message").
[Test]
public void ShouldVerifyDebugMessage()
{
this.Logger.LogDebug("Log Message");
this.MockLogger.VerifyLog().DebugWasCalled().MessageEquals("Log Message");
}
To verify that the desired log method was called a certain amount of times just verify the mock instance
using VerifyLog().DebugWasCalled().Times(2).
[Test]
public void ShouldVerifyDebugCalledTimes()
{
this.Logger.LogDebug("Log Message");
this.Logger.LogDebug("Log Message");
this.MockLogger.VerifyLog().DebugWasCalled().Times(2);
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.0)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Moq (>= 4.20.72)
-
net8.0
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.0)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Moq (>= 4.20.72)
-
net9.0
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.0)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Moq (>= 4.20.72)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0 | 546 | 12/9/2025 |
| 9.0.3 | 10,079 | 3/3/2025 |
| 9.0.2 | 2,252 | 11/16/2024 |
| 9.0.1 | 692 | 11/14/2024 |
| 9.0.0 | 709 | 11/14/2024 |
| 1.2.4 | 2,447 | 11/1/2024 |
| 1.2.3 | 8,130 | 7/9/2024 |
| 1.2.2 | 2,033 | 3/19/2024 |
| 1.2.1 | 2,029 | 11/16/2023 |
| 1.2.0 | 43,917 | 1/18/2023 |
| 1.1.3 | 1,219 | 11/19/2022 |
| 1.1.2 | 994 | 10/12/2022 |
| 1.1.1 | 2,262 | 6/3/2022 |
| 1.1.0 | 1,183 | 5/7/2022 |
| 1.0.4 | 855 | 4/14/2022 |
| 1.0.3 | 574 | 4/12/2022 |
| 1.0.2 | 640 | 12/16/2021 |