Muonroi.Logging
1.0.0-alpha.16
dotnet add package Muonroi.Logging --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Logging -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Logging" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Logging" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Logging" />
paket add Muonroi.Logging --version 1.0.0-alpha.16
#r "nuget: Muonroi.Logging, 1.0.0-alpha.16"
#:package Muonroi.Logging@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Logging&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Logging&version=1.0.0-alpha.16&prerelease
Muonroi.Logging
Structured logging implementation for Muonroi:
IMLog<T>wrapper, ambient property scopes, and aMicrosoft.Extensions.Loggingbridge that auto-enriches every log line with tenant, user, and correlation context.
Muonroi.Logging wires a thin, opinionated layer on top of Microsoft.Extensions.Logging. It registers IMLog<T> — a drop-in structured logger with Info/Warn/Error/Debug/InfoTrace helpers — and automatically pushes TenantId, UserId, and CorrelationId from the ambient ISystemExecutionContextAccessor into every log scope. It also provides IMLogContext for pushing arbitrary key-value properties, IMLogFactory for creating loggers by type or category name, and ILogScopeFactory for building scopes from property dictionaries.
Installation
dotnet add package Muonroi.Logging --prerelease
Quick Start
using Muonroi.Core.Abstractions.Context;
using Muonroi.Logging;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Register IMLogContext, IMLog<T>, IMLogFactory, and ILogScopeFactory.
builder.Logging.AddMuonroiLogging();
// IMLog<T> auto-enriches log lines with TenantId/UserId/CorrelationId from the
// ambient execution context. AddCoreServices() provides this automatically;
// register the default accessor explicitly when using logging in isolation.
builder.Services.AddSingleton<ISystemExecutionContextAccessor, SystemExecutionContextAccessor>();
builder.Services.AddControllers();
WebApplication app = builder.Build();
app.MapControllers();
app.Run();
Inject IMLog<T> into any service or controller:
using Muonroi.Logging.Abstractions;
public sealed class OrderService(IMLog<OrderService> log)
{
public void Process(int orderId)
{
log.Debug("Starting order {OrderId}", orderId);
using IMLogContextScope scope = log.BeginProperty("OrderId", orderId);
log.Info("Processing order inside scoped property");
try
{
// ...
}
catch (Exception ex)
{
log.Error(ex, "Order {OrderId} failed", orderId);
}
}
}
Create a logger for an arbitrary category name via IMLogFactory:
public sealed class PaymentProcessor(IMLogFactory logFactory)
{
public void Charge(string provider)
{
IMLog providerLog = logFactory.CreateLogger(provider);
providerLog.Info("Charging via {Provider}", provider);
}
}
Features
IMLog<T>— category-typed structured logger withInfo,Warn,Error,Debug, andInfoTracehelper methods, all delegating to the innerILogger<T>- Automatic ambient enrichment — every log call acquires a scope carrying
TenantId,UserId, andCorrelationIdfromISystemExecutionContextAccessor IMLogContext.PushProperty/PushProperties— push arbitrary key-value pairs as structured log scopes that are removed onDisposeIMLog.BeginProperty— shorthand onIMLogforIMLogContext.PushPropertyIMLogFactory— createsIMLog<T>orIMLogby category name; useful for dynamic or per-provider loggersILogScopeFactory— creates scopes fromIReadOnlyDictionary<string, object?>for bulk property injectionLogPropertyConventions— well-known property key constants (TenantId,UserId,CorrelationId,TraceSessionId,RuleCode,RequestName)- Trace session integration — when
IMTraceContextis present,Info/Warn/Error/Debug/InfoTracealso record messages to the active trace session
Configuration
Call AddMuonroiLogging() on the ILoggingBuilder (typically builder.Logging):
builder.Logging.AddMuonroiLogging();
This registers the following singletons:
| Registration | Implementation |
|---|---|
IMLogContext |
MLogContext |
IMLog<> (open generic) |
MLog<> |
IMLogFactory |
MLogFactory |
ILogScopeFactory |
MLogScopeFactory |
No appsettings.json section is required. Log level filtering and sinks are controlled by the standard Microsoft.Extensions.Logging configuration already present in your host.
MLog<T> requires ISystemExecutionContextAccessor to be registered. When using Muonroi.Core in the same host, AddCoreServices() registers it automatically. For isolated setups (tests, samples), register the default implementation manually:
builder.Services.AddSingleton<ISystemExecutionContextAccessor, SystemExecutionContextAccessor>();
API Reference
| Type | Purpose |
|---|---|
IMLog |
Base structured logger: Info, Warn, Error, Debug, InfoTrace, BeginProperty |
IMLog<T> |
Category-typed variant of IMLog; extends ILogger<T> |
IMLogFactory |
Creates IMLog<T> or IMLog by category name |
IMLogContext |
Pushes properties into the ambient log scope via PushProperty / PushProperties |
IMLogContextScope |
Disposable scope returned by PushProperty; removes the property on Dispose |
ILogScopeFactory |
Creates scopes from a property dictionary via BeginScope |
LogPropertyConventions |
String constants for TenantId, UserId, CorrelationId, TraceSessionId, RuleCode, RequestName |
MLogServiceCollectionExtensions |
ILoggingBuilder.AddMuonroiLogging() extension method |
Samples
- Quickstart.Logging — ASP.NET Core API demonstrating
IMLog<T>emit,BeginPropertyscoped logging, andIMLogFactorycategory-name creation
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Logging.Abstractions— contracts only (IMLog,IMLog<T>,IMLogFactory,IMLogContext,IMLogContextScope,ILogScopeFactory,LogPropertyConventions); reference this instead ofMuonroi.Loggingin library projects that only consume the interfacesMuonroi.Core.Abstractions— providesISystemExecutionContextAccessorandISystemExecutionContextused for ambient context enrichment
License
Apache-2.0. See LICENSE-APACHE.
| 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 (>= 10.0.3)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Logging.Abstractions (>= 1.0.0-alpha.16)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Muonroi.Logging:
| Package | Downloads |
|---|---|
|
Muonroi.Core
Core services implementation: datetime, JSON serialization, logging wrappers, and system execution context for Muonroi applications. |
|
|
Muonroi.Mediator
Mediator pattern implementation for Muonroi: command/query dispatching, pipeline behaviors, and validation integration. |
|
|
Muonroi.Pdf
HTML/CSS to PDF layout engine: box-tree construction, pagination, and rendering coordination for Muonroi applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 186 | 6/22/2026 |
| 1.0.0-alpha.15 | 212 | 5/31/2026 |
| 1.0.0-alpha.14 | 202 | 5/15/2026 |
| 1.0.0-alpha.13 | 168 | 5/2/2026 |
| 1.0.0-alpha.12 | 104 | 4/2/2026 |
| 1.0.0-alpha.11 | 153 | 4/2/2026 |
| 1.0.0-alpha.9 | 94 | 3/30/2026 |
| 1.0.0-alpha.8 | 323 | 3/28/2026 |
| 1.0.0-alpha.7 | 85 | 3/27/2026 |
| 1.0.0-alpha.5 | 74 | 3/27/2026 |
| 1.0.0-alpha.4 | 72 | 3/27/2026 |
| 1.0.0-alpha.3 | 78 | 3/27/2026 |
| 1.0.0-alpha.2 | 79 | 3/26/2026 |
| 1.0.0-alpha.1 | 113 | 3/8/2026 |