Junction Logger

The junction logger fires before and after each junction in a train, logging structured JunctionMetadata entries. This gives you per-junction observability: which junction is running, how long it took, what its Railway state was, and optionally what it returned.

Registration

dotnet add package Trax.Effect.JunctionProvider.Logging
services.AddTrax(trax => trax
    .AddEffects(effects => effects
        .AddJunctionLogger(serializeJunctionData: true)
    )
);

The serializeJunctionData Option

When serializeJunctionData is false (the default), the junction logger records timing, types, and Railway state but not the actual output values.

When true, after each junction completes, the logger serializes the junction's output to JSON and stores it in JunctionMetadata.OutputJson. This is useful for debugging — you can see exactly what each junction produced — but adds serialization overhead per junction.

How It Works

The junction logger is a junction effect provider, not a regular effect provider. It hooks into the EffectJunction lifecycle rather than the train-level Track/SaveChanges cycle.

Before each junction runs, the logger creates a JunctionMetadata entry with:

FieldDescription
NameJunction class name
TrainNameParent train name
TrainExternalIdParent train's external GUID
InputType / OutputTypeThe junction's generic type arguments
StartTimeUtcWhen the junction began

After the junction completes:

FieldDescription
EndTimeUtcWhen the junction finished
StateRailway state — Right (success), Left (failure), or Bottom
HasRanWhether the junction actually executed (skipped on failure track)
OutputJsonSerialized output (only if serializeJunctionData: true)

The completed JunctionMetadata is logged at the configured log level via ILogger<JunctionLoggerProvider>.

Requires EffectJunction

The junction logger only fires on junctions that inherit from EffectJunction<TIn, TOut>. If your junctions use the base Junction<TIn, TOut>, the logger has nothing to hook into and won't produce any output.

See Junctions: EffectJunction vs Junction for the difference between the two.

When to Use It

  • Debugging slow trains — The timing data shows which junction is the bottleneck.
  • Tracing failures — The Railway state tells you exactly where and why a train switched to the left track.
  • Development — Pair with serializeJunctionData: true to see junction-by-junction data flow through the chain.

SDK Reference

> AddJunctionLogger