Momkay.LoggingProxy
1.2.0
dotnet add package Momkay.LoggingProxy --version 1.2.0
NuGet\Install-Package Momkay.LoggingProxy -Version 1.2.0
<PackageReference Include="Momkay.LoggingProxy" Version="1.2.0" />
<PackageVersion Include="Momkay.LoggingProxy" Version="1.2.0" />
<PackageReference Include="Momkay.LoggingProxy" />
paket add Momkay.LoggingProxy --version 1.2.0
#r "nuget: Momkay.LoggingProxy, 1.2.0"
#:package Momkay.LoggingProxy@1.2.0
#addin nuget:?package=Momkay.LoggingProxy&version=1.2.0
#tool nuget:?package=Momkay.LoggingProxy&version=1.2.0
Momkay.LoggingProxy
A lightweight proxy-based logging interceptor for .NET service interfaces. mIt automatically logs method calls, parameters, execution time, and exceptions — without cluttering your service code.
Features
- Logs method entry, arguments, and execution duration
- Logs exceptions with full stack trace
- Works with sync and async (
Task
,Task<T>
) methods - Attribute-based control:
[NoLog]
— skip logging[Log(LogLevel.Debug)]
— override log level
- Console log coloring (optional, terminal-dependent)
- No external dependencies
- Zero boilerplate with
AddLoggedServices(...)
Installation
dotnet add package Momkay.LoggingProxy
Setup
In your Program.cs
(or startup configuration):
using Momkay.LoggingProxy.Core;
builder.Services.AddLoggedServices(typeof(IMyService).Assembly);
This will:
- Scan all classes in the given assembly
- Match them with interfaces named
I[ClassName]
- Register them automatically with
Scoped
lifetime - Wrap them in a proxy that injects structured logging
⚠️ You do not need to call
AddScoped<IMyService, MyService>()
manually.
Usage Example
Interface
public interface IMyService
{
Task DoWorkAsync();
Task InternalHelper();
}
Implementation
public class MyService : IMyService
{
[Log(LogLevel.Debug)]
public async Task DoWorkAsync()
{
// This will be logged at Debug level
}
[NoLog]
public Task InternalHelper()
{
// This will be skipped in logging
return Task.CompletedTask;
}
}
Attributes
Attribute | Description |
---|---|
[NoLog] |
Excludes method from logging |
[Log(Level)] |
Overrides log level (default: Info) |
Return Value Logging
You can log method return values by setting:
Per method:
[Log(includeReturnValue: true)]
public Task<string> GetTokenAsync() { ... }
Globally:
LoggingProxyConfig.LogReturnValuesByDefault = true;
Console Output
By default, logs are written via ILogger<T>
.
For better readability, the proxy includes optional ANSI colors (cyan/green/red) for:
- Entry
▶
- Success
✔
- Errors
❌
Colors only appear if your console supports ANSI (e.g. VS Code terminal, Windows Terminal, bash).
To disable colors globally:
set LOGGING_PROXY_COLORS=0
Requirements
- .NET 6 or later (or .NET Standard 2.1 for library use)
- Interface-based registration pattern (e.g.
IFooService
/FooService
) Microsoft.Extensions.Logging
(already standard in ASP.NET Core)
License
MIT — Use it, extend it, improve it. Contributions welcome!
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
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.