Muonroi.Logging.Abstractions
2.0.2
dotnet add package Muonroi.Logging.Abstractions --version 2.0.2
NuGet\Install-Package Muonroi.Logging.Abstractions -Version 2.0.2
<PackageReference Include="Muonroi.Logging.Abstractions" Version="2.0.2" />
<PackageVersion Include="Muonroi.Logging.Abstractions" Version="2.0.2" />
<PackageReference Include="Muonroi.Logging.Abstractions" />
paket add Muonroi.Logging.Abstractions --version 2.0.2
#r "nuget: Muonroi.Logging.Abstractions, 2.0.2"
#:package Muonroi.Logging.Abstractions@2.0.2
#addin nuget:?package=Muonroi.Logging.Abstractions&version=2.0.2
#tool nuget:?package=Muonroi.Logging.Abstractions&version=2.0.2
Muonroi.Logging.Abstractions
Contracts-only package that defines the
IMLog<T>,IMLogContext, and log-property conventions used across the Muonroi ecosystem.
This package ships the logging interfaces and property-key constants that consumer libraries depend on at compile time — no runtime behavior is included. Services that want structured logging take IMLog<T> by constructor injection; middleware and request handlers push ambient properties through IMLogContext. The concrete implementation lives in Muonroi.Logging.
Installation
dotnet add package Muonroi.Logging.Abstractions --prerelease
Quick Start
This package defines contracts only. Implement or inject IMLog<T> in your service; for tests or AOT scenarios you can supply a no-op implementation without taking a dependency on any logging provider:
using Muonroi.Logging.Abstractions;
using Microsoft.Extensions.Logging;
// Minimal no-op implementation — useful in tests or AOT hosts.
internal sealed class NoOpLog<T> : IMLog<T>
{
private sealed class NullScope : IMLogContextScope
{
public static readonly NullScope Instance = new();
public void Dispose() { }
}
public IMLogContextScope BeginProperty(string key, object? value) => NullScope.Instance;
public void Info(string messageTemplate, params object?[] args) { }
public void Warn(string messageTemplate, params object?[] args) { }
public void Error(Exception? ex, string messageTemplate, params object?[] args) { }
public void Debug(string messageTemplate, params object?[] args) { }
public void InfoTrace(string messageTemplate, params object?[] args) { }
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => NullScope.Instance;
public bool IsEnabled(LogLevel logLevel) => false;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
Exception? exception, Func<TState, Exception?, string> formatter) { }
}
// Register with open-generic DI so every IMLog<T> request is satisfied:
services.AddSingleton(typeof(IMLog<>), typeof(NoOpLog<>));
For full structured logging in an ASP.NET Core application, use AddMuonroiLogging() from Muonroi.Logging:
builder.Logging.AddMuonroiLogging();
Features
IMLog/IMLog<T>— structured logging interface extendingILogger/ILogger<T>with shorthand methods (Info,Warn,Error,Debug,InfoTrace) andBeginPropertyscoping.IMLogFactory— factory interface for creatingIMLoginstances by type or category name.IMLogContext— ambient property bag; push key-value pairs into the logging context withPushProperty/PushProperties.IMLogContextScope— disposable scope returned byBeginProperty/PushProperty; disposing it removes the property from the context.IInterceptedLogWriter— interceptor abstraction for custom logging sinks; the signature takesCategoryNamefor contextual routing.LogEvent— performance-oriented model inMuonroi.Logging.Abstractions.ModelsimplementingReset()for aggressiveObjectPoolreuse.LogPropertyConventions— static constants for standard structured-log property keys:TenantId,UserId,CorrelationId,TraceSessionId,RuleCode,RequestName.
API Reference
| Type | Purpose |
|---|---|
IMLog |
Base structured-logging interface; extends ILogger. Adds Info, Warn, Error, Debug, InfoTrace, and BeginProperty. |
IMLog<T> |
Generic variant; extends both IMLog and ILogger<T>. Inject this in application services. |
IMLogFactory |
Creates IMLog and IMLog<T> instances by type parameter or category name string. |
IMLogContext |
Ambient context bag. PushProperty(key, value) and PushProperties(dict) attach properties to all log events within the returned scope. |
IMLogContextScope |
Disposable returned by BeginProperty / PushProperty. Dispose to remove the pushed property from the ambient context. |
IInterceptedLogWriter |
Interceptor abstraction for custom logging sinks, taking CategoryName in its signature for contextual routing. |
LogEvent |
Performance-oriented model (in Models) implementing Reset() for aggressive ObjectPool reuse to minimize allocation overhead. |
LogPropertyConventions |
String constants: TenantId, UserId, CorrelationId, TraceSessionId, RuleCode, RequestName. |
Samples
- Quickstart.Logging — ASP.NET Core API that demonstrates
AddMuonroiLogging(),IMLog<T>injection, andIMLogContext.PushPropertyscopes. - Muonroi.Pdf.AotSample — shows a no-op
IMLog<T>open-generic registration for AOT / trimmed hosts that cannot use the full Serilog provider.
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Logging— concrete implementation; registersMLog<T>,MLogContext,MLogFactory, andILogScopeFactoryviabuilder.Logging.AddMuonroiLogging().
Ecosystem Combinations
+ Logging → Implementation Behind IMLog
Muonroi.Logging implements the IMLog<T> and IMLogFactory contracts defined here. Swap to a different implementation without changing any call sites.
+ Tenancy → IMLog Auto-Enriched with TenantId
When ITenantContext is active, all IMLog<T> implementations automatically scope log entries with the current tenant ID.
+ All Packages → Universal Logging Contract
Every Muonroi package accepts IMLog<T> instead of ILogger<T>, enabling consistent structured logging across the entire ecosystem.
Samples
License
Apache-2.0. See LICENSE-APACHE for details.
| 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 (>= 10.0.3)
NuGet packages (18)
Showing the top 5 NuGet packages that depend on Muonroi.Logging.Abstractions:
| Package | Downloads |
|---|---|
|
Muonroi.RuleEngine.Core
Rule Engine Core implementation for Muonroi.BuildingBlock |
|
|
Muonroi.Core.Abstractions
Core contracts, interfaces, and base types for the Muonroi ecosystem. Required by all Muonroi packages. |
|
|
Muonroi.Tenancy.Core
Shared-database multi-tenancy core: EF Core global filters, tenant context propagation, and quota tracking. |
|
|
Muonroi.Logging
Structured logging implementation for Muonroi: IMLog wrapper, log scope factory, and Serilog/Microsoft.Extensions.Logging bridge. |
|
|
Muonroi.Mediator
Mediator pattern implementation for Muonroi: command/query dispatching, pipeline behaviors, and validation integration. |
GitHub repositories
This package is not used by any popular GitHub repositories.