Nullean.Entities.Diagnostics 0.5.0

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

Nullean.Entities.Diagnostics

Nullean.Entities

Every rejected change and every missed deadline shows up in your logs, metrics and traces, under names OpenTelemetry subscribes to, without an OpenTelemetry dependency.

NuGet

Without this package, a violation your service sees at runtime is a Result.Fail someone has to remember to log, and a deadline a TemporalMonitor reaches on its timer is seen by nobody. This package reports both through the platform's own abstractions: structured ILogger records with stable event ids, counters on a System.Diagnostics.Metrics meter named Nullean.Entities, and an event on the current Activity.

It builds on Nullean.Entities and Microsoft.Extensions.Logging.Abstractions, nothing else. It is optional, it uses no reflection, and it is trim and NativeAOT clean.

Install

Targets net10.0 and net11.0.

dotnet add package Nullean.Entities
dotnet add package Nullean.Entities.Diagnostics

Quick start

Register it once, and pass outcomes through ReportTo. It returns what it was given, so it chains.

using Nullean.Entities;
using Nullean.Entities.Diagnostics;

builder.Services.AddConstraintDiagnostics();     // logs to the "Nullean.Entities" category, meter from the host's IMeterFactory

public sealed class Accounts(ConstraintDiagnostics diagnostics)
{
    public Result<Account> Withdraw(Account account, decimal amount) =>
        Account.Constraints.Apply(account, a => a with { Balance = a.Balance - amount }).ReportTo(diagnostics);
}

public sealed class Shipments(ConstraintDiagnostics diagnostics, TimeProvider time)
{
    private readonly TemporalMonitor<OrderEvent> _monitor = new TemporalMonitor<OrderEvent>(OrderRules.All, time).ReportTo(diagnostics);

    public void Confirmed(int id) => _monitor.Observe(new OrderEvent.Confirmed(id));
}

A withdrawal below zero logs event 4100 (ConstraintViolated: EntityType, Rule, Severity, Member, ViolationMessage) and counts one entities.violations and one entities.rejections. A confirmed order that does not ship in time logs event 4110 (TemporalRuleViolated) at the deadline's own instant, from the monitor's timer, with no further event needed.

Then subscribe in OpenTelemetry by the meter's name:

builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics => metrics.AddMeter(ConstraintDiagnostics.MeterName))   // "Nullean.Entities"
    .WithLogging()
    .UseOtlpExporter();

What you get

  • ConstraintDiagnostics(ILogger logger, IMeterFactory? meterFactory = null, ConstraintDiagnosticsOptions? options = null), and services.AddConstraintDiagnostics(configure) for a singleton.
  • Result<T>.ReportTo(diagnostics) and ApplyOutcome<T>.ReportTo(diagnostics): a failure counts one rejection and reports its violations; an Applied reports the warnings and hints it was accepted with.
  • diagnostics.Report<T>(violations): for Validate, Check or a caught ConstraintViolationException.
  • TemporalMonitor<TEvent>.ReportTo(diagnostics) and diagnostics.Watch(monitor) (an IDisposable): every violation the monitor reaches, deadlines included.
  • Counters entities.violations (tags entities.rule, entities.severity, entities.type) and entities.rejections (tag entities.type) on the meter Nullean.Entities.
  • Log event ids in ConstraintDiagnosticsEvents: 4100, 4101 (with evidence), 4110 (temporal), 4111 (temporal, with evidence).
  • An entities.violation event on Activity.Current, when there is one that records.

Pitfalls and limits

  • Violation.Evidence can hold personal data, so it is not logged unless IncludeEvidence = true, and it is never a metric tag or a trace event.
  • Log levels are fixed: Warning for an error and for a temporal violation, Information for a warning, Debug for a hint. Filter with the usual logging rules.
  • ReportTo on a monitor reports until the monitor is disposed; use Watch to stop earlier.
  • The monitor reports on the thread that caused the change, the TimeProvider's timer for a deadline.
  • MonitoredConstraintSet<TEvent> in Nullean.Entities.Reactive is not hooked.

Learn more

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.  net11.0 is compatible. 
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
0.5.0 79 11/12/2026
0.4.0 90 11/11/2026
0.3.0 97 11/4/2026