AttributeLogger 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AttributeLogger --version 1.0.0
                    
NuGet\Install-Package AttributeLogger -Version 1.0.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="AttributeLogger" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AttributeLogger" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AttributeLogger" />
                    
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 AttributeLogger --version 1.0.0
                    
#r "nuget: AttributeLogger, 1.0.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 AttributeLogger@1.0.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=AttributeLogger&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AttributeLogger&version=1.0.0
                    
Install as a Cake Tool

AttributeLogger

  1. Purpose
  2. Attributes
  3. Usage

This library provides a simple Aspect-Oriented Programming(AOP) approach to logging of C# classes and methods, using AspectCore.DynamicProxy to intercept method calls and integrates with Microsoft.Extensions.Logging. It automatically logs nested exceptions and propagates them by default. The standard logging info is formatted as follow

InvocationGuid: [f5c7e3c2-0d4f-45e8-9a2d-123456789abc] MyApp.Services.OrderService.CreateOrder Start

InvocationGuid: [f5c7e3c2-0d4f-45e8-9a2d-123456789abc] MyApp.Services.OrderService.CreateOrder Param firstParam: ""

InvocationGuid: [f5c7e3c2-0d4f-45e8-9a2d-123456789abc] MyApp.Services.OrderService.CreateOrder End

Main Purpose

The main purpose is to:

  • Automatically log method start, end, and failures.
  • Allow flexible logging levels (Trace, Debug, Information, Warning, Error, Critical).
  • Enable or disable logging at the method level.
  • Optionally log method parameters.
  • Correlate logs across method calls using a correlation GUID.

Attributes

LogAttribute

This is the beating heart of this library. It's responsable of the whole logging system and specifies the logging level.

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] public class LogAttribute : AbstractInterceptorAttribute { public LogLevel LogLevel { get; set; }

 public LogAttribute(LogLevel logLevel)
 {
     LogLevel = logLevel;
 }

}

DisableLogAttribute

this method avoids unwanted methods logging, do not need further parameters.

[AttributeUsage(AttributeTargets.Method, Inherited = false)] public class DisableLogAttribute : Attribute { // This attribute is used to disable logging for specific methods }

LogParametersAttribute

This method enables method parameters input logging, to a specific level. Also allows to handle exception propagation

[AttributeUsage(AttributeTargets.Method, Inherited = false)] public class LogParametersAttribute : Attribute { public LogLevel LogLevel { get; set; } public bool RaiseExceptions { get; set; } public LogParametersAttribute() { } public LogParametersAttribute(LogLevel logLevel = LogLevel.Information, bool raiseExceptions = false) { LogLevel = logLevel; RaiseExceptions = raiseExceptions; } }

Usage

  1. Decorate Classes

[Log(LogLevel.Information)] public class MyServiceService { public void CreateOrder(string customerId) { // Logs automatically } } this will create the following logging

InvocationGuid: [f5c7e3c2-0d4f-45e8-9a2d-123456789abc] MyApp.Services.MyServiceService.CreateOrder Start InvocationGuid: [f5c7e3c2-0d4f-45e8-9a2d-123456789abc] MyApp.Services.MyServiceService.CreateOrder End

  1. Decorate Methods (Optional)

[Log(LogLevel.Information)] public class MyServiceService { public void CreateOrder(string customerId) { MyCommand.CreateOrder(customerId); }

  public void CreateOrder(string OrderId)
 {
     // Logs automatically
 }

}

[Log(LogLevel.Information)] public class MyCommand(){

[DisableLog]
public CreateOrder(string customerId){
   WriteToDatabase(customerId);
 }   

}

Register AspectCore In your Program.cs or Startup.cs: services.AddDynamicProxy(); // Enables AspectCore interception

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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