FlowLite.Diagnostics 8.0.0

dotnet add package FlowLite.Diagnostics --version 8.0.0
                    
NuGet\Install-Package FlowLite.Diagnostics -Version 8.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="FlowLite.Diagnostics" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlowLite.Diagnostics" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FlowLite.Diagnostics" />
                    
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 FlowLite.Diagnostics --version 8.0.0
                    
#r "nuget: FlowLite.Diagnostics, 8.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 FlowLite.Diagnostics@8.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=FlowLite.Diagnostics&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FlowLite.Diagnostics&version=8.0.0
                    
Install as a Cake Tool

FlowLite.Diagnostics

FlowLite.Diagnostics is an extension for FlowLite that adds logging, telemetry, observability, and global FSM diagnostics. It allows you to monitor the full lifecycle of your finite state machine, including transitions, errors, entity changes, and deletions.

Features

  • Console logging of all FSM events.
  • Telemetry metrics via System.Diagnostics.Metrics (OpenTelemetry-compatible).
  • DiagnosticListener events (StateChanged, EntityChanged, EntityDeleted).
  • Integration with ILogger (Microsoft.Extensions.Logging).
  • Global diagnostics: auto-attach listeners to all FSMs via FlowLite global hook.
  • Extensibility via custom IDiagnosticsFlowLiteListener.

Installation

To install the latest version of the FlowLite.Diagnostics NuGet package:

NuGet Package Manager

Install-Package FlowLite.Diagnostics -Version 8.0.0

.NET CLI

dotnet add package FlowLite.Abstractions --version 8.0.0
dotnet add package FlowLite.Diagnostics --version 8.0.0

Usage Guide

Global setup in ASP.NET Core

services.AddFlowLiteDiagnostics<[State], [Trigger], [Key], [Entity]>(opt =>
{
    opt.EnableGlobalDiagnostics = true;
    opt.Telemetry.Enabled = true;
    opt.Logging.Enabled = true;
    opt.Logging.UseConsole = true;
    opt.Logging.UseLogger = true;
    opt.Logging.LoggerFactory = services.BuildServiceProvider().GetRequiredService<ILoggerFactory>();
    opt.DiagnosticObserver.Enabled = true;
});

After registration, all state machines created will automatically get hooked into diagnostics. Sample:

services.AddFlowLiteDiagnostics<OrderState, OrderTrigger, int, Order>(opt =>
{
    opt.EnableGlobalDiagnostics = true;
    opt.Telemetry.Enabled = true;
    opt.Logging.Enabled = true;
    opt.Logging.UseConsole = true;
    opt.Logging.UseLogger = true;
    opt.Logging.LoggerFactory = services.BuildServiceProvider().GetRequiredService<ILoggerFactory>();
    opt.DiagnosticObserver.Enabled = true;
});

Emitted Metrics (OpenTelemetry-compatible)

  • fsm_transitions_total - number of FSM transitions.
  • fsm_failures_total - number of failed FSM transitions.
  • fsm_state_changed_total - number of state changes.
  • fsm_entity_changed_total - number of entity updates.
  • fsm_entity_deleted_total- number of entity deletions.
  • fsm_transition_failed_total - number of failed transitions.

Telemetry (only for state machine)

fsm.UseTelemetry(new TelemetryOptions()
{
    Enabled = true, 
    Source = "FlowLite.FSM"
});

or

fsm.UseTelemetry();

Console Logging (only for state machine)

fsm.UseLogging(new LoggingOptions()
{
    Enabled = true,
    UseConsole = true,
    UseLogger = false
});

or

fsm.UseConsoleLogging();

Using ILogger (only for state machine)

fsm.UseLogging(new LoggingOptions()
{
    Enabled = true,
    UseConsole = true,
    UseLogger = true,
    LoggerFactory = services.GetRequiredService<ILoggerFactory>()
});

Diagnostic observer (only for state machine)

fsm.UseDiagnosticObserver(new DiagnosticObserverOptions()
{
    Enabled = true,
    Source = "FlowLite.Diagnostics"
});

or

fsm.UseDiagnosticObserver();

Register a Custom Listener

services.AddFlowLiteDiagnostics<OrderState, OrderTrigger, int, Order>(opt =>
{
    opt.EnableGlobalDiagnostics = true;
    opt.Telemetry.Enabled = true;
    opt.Logging.Enabled = true;
    opt.Logging.UseConsole = true;
    opt.Logging.UseLogger = true;
    opt.Logging.LoggerFactory = services.BuildServiceProvider().GetRequiredService<ILoggerFactory>();
    opt.DiagnosticObserver.Enabled = true;
    opt.CustomListeners.Add(new MyCustomFlowDiagnosticsListener());
});

Use CustomListeners to add a custom listener (based on IDiagnosticsFlowLiteListener)


License

This project is licensed under the MIT License.

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
8.0.0 174 4/20/2025

- Added support for .NET 8.0;
           - Added support for telemetry, logging, and event tracking.
           - Integrated support for OpenTelemetry via System.Diagnostics.Metrics.
           - Console, ILogger, and DiagnosticObserver event hooks.
           - Global FSM diagnostics configuration and listeners.