FractalDataWorks.MessageLogging.SourceGenerators 0.4.0-preview.6

This is a prerelease version of FractalDataWorks.MessageLogging.SourceGenerators.
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 FractalDataWorks.MessageLogging.SourceGenerators --version 0.4.0-preview.6
                    
NuGet\Install-Package FractalDataWorks.MessageLogging.SourceGenerators -Version 0.4.0-preview.6
                    
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="FractalDataWorks.MessageLogging.SourceGenerators" Version="0.4.0-preview.6">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FractalDataWorks.MessageLogging.SourceGenerators" Version="0.4.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="FractalDataWorks.MessageLogging.SourceGenerators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 FractalDataWorks.MessageLogging.SourceGenerators --version 0.4.0-preview.6
                    
#r "nuget: FractalDataWorks.MessageLogging.SourceGenerators, 0.4.0-preview.6"
                    
#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 FractalDataWorks.MessageLogging.SourceGenerators@0.4.0-preview.6
                    
#: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=FractalDataWorks.MessageLogging.SourceGenerators&version=0.4.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FractalDataWorks.MessageLogging.SourceGenerators&version=0.4.0-preview.6&prerelease
                    
Install as a Cake Tool

FractalDataWorks.MessageLogging.SourceGenerators

Source generator that creates logger methods returning IGenericMessage. Fork of Microsoft's LoggerMessage source generator extended for the FractalDataWorks pattern where every logged message is also returned for Result integration.

Overview

This Roslyn incremental source generator processes methods decorated with [MessageLogging] and generates implementation code that:

  1. Logs to ILogger using Microsoft.Extensions.Logging
  2. Returns an IGenericMessage containing the same message text

Target Framework

  • netstandard2.0 (required for Roslyn source generators)

Installation

Reference this package as an analyzer:

From Reference.MessageLogging.csproj:24-26:

<ItemGroup>
  <PackageReference Include="FractalDataWorks.MessageLogging.SourceGenerators" />
</ItemGroup>

Usage

Define a partial class with partial methods decorated with [MessageLogging]:

From OrderLog.cs:22-37:

public static partial class OrderLog
{
    // =========================================================================
    // DEBUG: Detailed internal operations
    // =========================================================================

    /// <summary>
    /// Logs when order processing begins.
    /// </summary>
    [MessageLogging(
        EventId = 8001,
        Level = LogLevel.Debug,
        Message = "Starting order processing for order '{orderId}'")]
    public static partial IGenericMessage ProcessingStarted(
        ILogger logger,
        string orderId);

From OrderLog.cs:107-120:

    // =========================================================================
    // ERROR: Explicit failure modes (each one returns IGenericMessage for Result)
    // =========================================================================

    /// <summary>
    /// Logs when an order is not found.
    /// </summary>
    [MessageLogging(
        EventId = 8030,
        Level = LogLevel.Error,
        Message = "Order '{orderId}' not found")]
    public static partial IGenericMessage OrderNotFound(
        ILogger logger,
        string orderId);

Use in service code with the "log AND return" pattern:

From OrderService.cs:115-126:

    public IGenericResult<Order> GetOrder(string orderId)
    {
        // Simulate order not found
        if (orderId.StartsWith("NOTFOUND"))
        {
            // Log AND return failure - the message is both logged and returned
            return GenericResult<Order>.Failure(
                OrderLog.OrderNotFound(_logger, orderId));
        }

        return GenericResult<Order>.Success(new Order { OrderId = orderId, Status = "Found" });
    }

Generator Requirements

From LoggerMessageGenerator.Parser.cs:21:

The generator looks for methods with the attribute FractalDataWorks.MessageLogging.MessageLoggingAttribute.

From LoggerMessageGenerator.Parser.cs:275-281:

// Validate return type is IGenericMessage or compatible
if (!IsCompatibleReturnType(logMethodSymbol.ReturnType, genericMessageSymbol))
{
    // logging methods must return IGenericMessage or a type that implements it
    Diag(DiagnosticDescriptors.LoggingMethodMustReturnVoid, method.ReturnType.GetLocation());
    keepMethod = false;
}

Methods must:

  • Be partial methods
  • Return IGenericMessage or a type implementing it
  • Have an ILogger parameter (for static methods) or class field
  • Not be generic

Generated Code

The generator creates implementation that logs to ILogger and returns IGenericMessage:

From LoggerMessageGenerator.Emitter.cs:487-493:

            _builder.Append($@"
            {nestedIndentation}return new global::FractalDataWorks.Messages.GenericMessage(
                {nestedIndentation}    {severityMapping},
                {nestedIndentation}    __messageText,
                {nestedIndentation}    {eventName},
                {nestedIndentation}    null);
        {nestedIndentation}}}");
  • FractalDataWorks.MessageLogging.Abstractions - Contains the [MessageLogging] attribute
  • FractalDataWorks.Messages - Contains IGenericMessage and GenericMessage
  • FractalDataWorks.Results - Contains IGenericResult<T> for Result integration

API Reference

See MessageLogging wiki section for complete documentation.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (19)

Showing the top 5 NuGet packages that depend on FractalDataWorks.MessageLogging.SourceGenerators:

Package Downloads
CyberdyneDevelopment.Mc3Po.Tools.Abstractions

Tool abstractions for FractalDataWorks Roslyn development tools. Provides TypeCollections for tool categories and parameter types.

CyberdyneDevelopment.Mc3Po.Protocols

Protocol infrastructure for mc3-po - base classes, provider, and ServiceType integration

CyberdyneDevelopment.Mc3Po.Protocols.Plane

Plane protocol implementation for mc3-po - project management integration with Plane

CyberdyneDevelopment.Mc3Po.Protocols.GitLab

GitLab protocol implementation for mc3-po - source control and project management integration

CyberdyneDevelopment.Mc3Po.Protocols.GitHub

Development tools and utilities for the FractalDataWorks ecosystem. Build:

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
Loading failed