Innovian.Aspects.Logging.Fabric 2024.10.29.1

dotnet add package Innovian.Aspects.Logging.Fabric --version 2024.10.29.1                
NuGet\Install-Package Innovian.Aspects.Logging.Fabric -Version 2024.10.29.1                
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="Innovian.Aspects.Logging.Fabric" Version="2024.10.29.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Innovian.Aspects.Logging.Fabric --version 2024.10.29.1                
#r "nuget: Innovian.Aspects.Logging.Fabric, 2024.10.29.1"                
#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.
// Install Innovian.Aspects.Logging.Fabric as a Cake Addin
#addin nuget:?package=Innovian.Aspects.Logging.Fabric&version=2024.10.29.1

// Install Innovian.Aspects.Logging.Fabric as a Cake Tool
#tool nuget:?package=Innovian.Aspects.Logging.Fabric&version=2024.10.29.1                

<a href="https://innovian.net"> <p align="center"> <img src="https://innovian.net/img/bluelogo.svg" width="100px"/> </p> </a>

Innovian.Aspets.Logging

NuGet

Innovian.Aspects.Logging.Fabric

NuGet

Aspect and Fabric package pipeline

Build Status

This project is provided to the larger open-source community by Innovian.

This solution implements an aspect using Metalama targeting .NET 8 that provides logging capabilities to projects targeting Microsoft.Extensions.Logging using ILoggerFactory and/or ILogger. This project includes a single aspect intended for direct use, InjectLoggerAttribute (intended to be applied to a class) and a fabric that automatically applies this attribute to every non-static class and non-static method across whatever project that targets it.

The attribute performs the following:

  • Automatically wraps eligible methods in try/catch blocks
  • Injects an optional instance of ILoggerFactory into all constructors of an eligible class
  • Injects and instantiates an ILogger as a private field on the class from the ILoggerFactory or from a NullLoggerFactory instance if the injected ILoggerFactory is null
  • Creates a stopwatch in each method that times and records, via the ILogger field, how long it takes a given method to execute

Metalama License

The team at Postsharp were kind enough to grant this project an open source license meaning that this namespace can be built with any number of aspects without a Metalama license. However, you will a Metalama license to use this in your own project. Their free license allows up to 3 aspects at no cost. I've purchased a commercial license for their software for use at my own company and if you similarly find that this aspects adds sufficient value to your own work, I encourage you to purchase licenses for your own team.

Note: The Innovian.Aspects.Logging project can be used with the free plan by decorating each class with [InjectLogger], but you'll need the cheapest paid plan to support the Fabric (automatic project-wide aspect decorating) used in Innovian.Aspects.Logging.Fabric as Fabrics are not supported in the free license.

Direct usage of the attribute

The following instructions detail how to use the InjectLoggerAttribute directly in those project. It's intended to be applied as an attribute to any classes (not records) in your project and will automatically apply the other attributes in the project. Direct usage of these other attributes isn't intended.

Installation

Using the .NET CLI tools:

dotnet add package Innovian.Aspects.Logging

Using the Package Manager Console:

Install-Package Innovian.Aspects.Logging

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on the project within your solution you wish to add the attribute to.
  3. Click on "Manage NuGet Packages...".
  4. Click on the "Browse" tab and search for "Innovian.Aspects.Logging".
  5. Click on the "Innovian.Aspects.Logging" package, select the appropriate version in the right-tab and click Install.

Usage

Simply apply the [InjectLogger] attribute to any non-static class you would like the logging capabilities added to. It's recommended that the class be marked with the partial keyword so that you're able to access the ILogger field on the type named _logger, but this isn't required.

Indirect usage via a Fabric

The following instructions detail how to use the Fabric-based approach to applying the InjectLoggerAttribute automatically throughout the project referencing this package. This fabric will automatically apply the aspect to all non-static classes and non-static methods.

Installation

Using the .NET CLI tools:

dotnet add package Innovian.Aspects.Logging.Fabric

Using the Package Manager Console:

Install-Package Innovian.Aspects.Logging.Fabric

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on the project within your solution you wish to add the attribute to.
  3. Click on "Manage NuGet Packages...".
  4. Click on the "Browse" tab and search for "Innovian.Aspects.Logging.Fabric".
  5. Click on the "Innovian.Aspects.Logging.Fabric" package, select the appropriate version in the right-tab and click Install.

Usage

No additional effort is necessary beyond installation of the Innovian.Aspects.Logging.Fabric package on the project. It will automatically identify all non-static classes to apply the [InjectLogger] attribute to automatically. In turn, this will perform the code generation functionality described above.

Notes

The fabric will only install to classes that have at least one method as there's little point to it being on the class otherwise.

Further, ecause we at Innovian also build functionality around Dapr Workflows and the Workflow base type requires parameterless constructors, the fabric will also neglect to apply to any type that implements an abstract base type called "Workflow".

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. 
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
2024.10.29.1 83 10/29/2024
2024.10.15.1 92 10/15/2024
2024.10.4.1 93 10/4/2024
2024.10.2.1 98 10/2/2024
2024.9.30.3 98 9/30/2024
2024.8.9.2 130 8/9/2024
2024.8.9.1 117 8/9/2024
2024.8.4.4 90 8/4/2024
2024.8.4.3 88 8/4/2024
2024.8.4.2 85 8/4/2024
2024.8.3.3 83 8/3/2024