简体   繁体   中英

How to log state transitions in Stateless (.NET state machine library)

I would like to have a log in database of state transitions of my workflow.

Where is the best place to trigger logging with Stateless ? Should it be set-up for each State configuration :

phoneCall.Configure(State.Connected)
    .OnEntry(() => StartCallTimer())
    .OnEntry(() => Log());

or there is some way to define it centrally for whole workflow once?

Any other input in this regard is welcome.

You can use the OnTransitioned trigger that will be fired on every transition as central logging facility.

_stateMachine.OnTransitioned(OnTransitionedAction);

void OnTransitionedAction(StateMachine<StateEnum, TriggerEnum>.Transition transition) {
    TriggerEnum trigger = transition.Trigger;
    StateEnum source = transition.Source;
    StateEnum dest = transition.Destination;
    // log trigger, source, destination
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM