Reference

AddJson

Package Trax.Effect.Provider.JsonNamespaces Trax.Effect.Provider.Json.Extensions, Trax.Effect.Provider.Json.Services.JsonEffectSource ServiceExtensions.cs, JsonEffectProvider.cs

Adds the JSON effect, which logs each model a train tracks (its Metadata, and anything else passed to Track) when the model's JSON has changed since the last save. Nothing is stored in the database.

Signature

public static TBuilder AddJson<TBuilder>(
    this TBuilder configurationBuilder
)
    where TBuilder : TraxEffectBuilder

Returns

TBuilder, the builder type it was called on.

Behavior

Registers the JSON effect's factory with AddEffect, as a toggleable effect, so the effect registry and the dashboard's Effects page can turn it off at runtime. Each run gets a JsonEffectProvider:

MemberDescription
Track(model)Serializes the model and keeps the JSON as its starting state
Update(model)Does nothing
SaveChanges(cancellationToken)Serializes every tracked model again and logs the masked JSON of each one that changed to ILogger<JsonEffectProvider>, as the string argument {Metadata}, at the effect log level
Dispose()Drops the tracked models

A run saves its effects twice, when its first row is written and when its outcome is, so the log shows a model as it started and as it ended. It cannot attribute a change to a junction. Every tracked model is serialized on every save, changed or not. The JSON compared is the effect configuration's serializer through TraxLogSerialization.ForLogging, which masks [TraxSensitive] members and writes the copies a train is run from as {"_omitted": true}. The log line carries that JSON string and never the model object, so a structured sink that destructures its arguments sees the masked copy only.

Example

services.AddTrax(trax => trax
    .AddEffects(effects => effects
        .UsePostgres(connectionString)
        .AddJson()
    )
    .AddMediator(typeof(IShipOrderTrain).Assembly)
);

See also