Cognitic.Tools.Logging.InMemory
1.0.0
dotnet add package Cognitic.Tools.Logging.InMemory --version 1.0.0
NuGet\Install-Package Cognitic.Tools.Logging.InMemory -Version 1.0.0
<PackageReference Include="Cognitic.Tools.Logging.InMemory" Version="1.0.0" />
<PackageVersion Include="Cognitic.Tools.Logging.InMemory" Version="1.0.0" />
<PackageReference Include="Cognitic.Tools.Logging.InMemory" />
paket add Cognitic.Tools.Logging.InMemory --version 1.0.0
#r "nuget: Cognitic.Tools.Logging.InMemory, 1.0.0"
#:package Cognitic.Tools.Logging.InMemory@1.0.0
#addin nuget:?package=Cognitic.Tools.Logging.InMemory&version=1.0.0
#tool nuget:?package=Cognitic.Tools.Logging.InMemory&version=1.0.0
Cognitic.Tools.Logging.InMemory
This is the description of what the code block changes: Populate README.md with a project overview, features, quick start and usage instructions.
Project overview
Cognitic.Tools.Logging.InMemory is a small utility library that provides an in-memory logger implementation for Microsoft.Extensions.Logging. It is intended primarily for unit tests and diagnostics where capturing and asserting log output is useful.
Key features
- Records log messages into a shared in-memory collection (
IList<LogInfo>). - Simple
ILoggerProviderandILoggerimplementations suitable for tests. - Easy to register with
ILoggingBuilderusing theAddInMemory()extension. - Target: .NET8 / C#12.
Public surface
LogInfo� a record that represents a captured log entry. Important properties:LogLevel(severity)Name(logger category)EventId(event identifier)Exception(optional)Message(formatted message)InMemoryLoggerProvider� creates and cachesInMemoryLoggerinstances.InMemoryLogger� writes log entries into the sharedIList<LogInfo>.InMemoryLoggerExtensions.AddInMemory()� registers the provider and the sharedIList<LogInfo>in the DI container.
Quick start
- Register the in-memory logger in your test's service collection:
IServiceCollection services = new ServiceCollection();
services.AddLogging(builder => builder.AddInMemory());
IServiceProvider provider = services.BuildServiceProvider();
var logger = provider.GetRequiredService<ILogger<Program>>();
var logs = provider.GetRequiredService<IList<LogInfo>>();
logger.LogInformation("Hello from tests");
// assert on `logs`
- Use
logsin assertions to verify message text, level, event id or exception.
Notes and usage tips
- The in-memory log collection is registered as a singleton
IList<LogInfo>. Multiple logger instances share the same collection, which makes it convenient to assert all recorded messages across categories. - The provider and logger are intentionally simple and do not implement advanced features such as structured scope storage or configurable filtering beyond
LogLevel.None.
Building and testing
- This solution targets .NET8. Build and run tests using the .NET CLI:
dotnet build
dotnet test
License
MIT
Contact
Use the repository issues to report bugs or request features.
| 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 was computed. 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 was computed. 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. |
-
net8.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
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 |
|---|