Momkay.LoggingProxy 1.2.0

dotnet add package Momkay.LoggingProxy --version 1.2.0
                    
NuGet\Install-Package Momkay.LoggingProxy -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Momkay.LoggingProxy" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Momkay.LoggingProxy" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Momkay.LoggingProxy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Momkay.LoggingProxy --version 1.2.0
                    
#r "nuget: Momkay.LoggingProxy, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Momkay.LoggingProxy@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Momkay.LoggingProxy&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Momkay.LoggingProxy&version=1.2.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.2.0 207 5/16/2025
1.0.2 199 5/16/2025
1.0.1 204 5/16/2025
1.0.0 234 5/15/2025