Skip to content

Commit

Permalink
log error when handler fails
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbright committed Jul 5, 2022
1 parent 2f3bc01 commit aaf42a1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Camunda.Worker/Execution/HandlerInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public async Task InvokeAsync()
}
catch (Exception e) when (!_context.ProcessingAborted.IsCancellationRequested)
{
LogHelper.LogFailedProcessing(_logger, _context.Task.Id, e);
executionResult = new FailureResult(e);
}

Expand All @@ -55,6 +56,13 @@ private static class LogHelper
"Finished processing of task {TaskId}"
);

private static readonly Action<ILogger, string, Exception?> FailedProcessing =
LoggerMessage.Define<string>(
LogLevel.Error,
new EventId(0),
"Failed processing of task {TaskId}"
);

public static void LogStartedProcessing(ILogger logger, string taskId)
{
if (logger.IsEnabled(LogLevel.Debug))
Expand All @@ -70,5 +78,13 @@ public static void LogFinishedProcessing(ILogger logger, string taskId)
FinishedProcessing(logger, taskId, null);
}
}

public static void LogFailedProcessing(ILogger logger, string taskId, Exception e)
{
if (logger.IsEnabled(LogLevel.Error))
{
FailedProcessing(logger, taskId, e);
}
}
}
}

0 comments on commit aaf42a1

Please sign in to comment.