Log handled MassTransit Saga exception

385 Views Asked by At

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 :) )

1

There are 1 best solutions below

0
Chris Patterson On BEST ANSWER

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())