masstransitautomatonymous

Log handled MassTransit Saga exception


I'm trying to figure out how to log handled exceptions. Currently the exception thrown from an Activity will be swallowed (for example if there are DI errors when trying to create the Acitivity).

What can I do to log the caught exceptions?

Initially(
    When(UpdateRequested)
        .Activity(x => x.OfType<HandleUpdateRequestActivity>())
        .TransitionTo(Updating)
        .Catch<Exception>(then => then.Finalize())
);

(Sorry for spamming the MassTransit tag lately :) )


Solution

  • First, simply to correct the terminology, it isn't swallowed, it's handled.

    The code above is catching the exception. If you want to log it, well, log it.

    .Catch<Exception>(then =>
        then.Then(context => Log(context.Exception))
            .Finalize())