Fix logger type
This commit is contained in:
parent
de4a4b3505
commit
9f841c70c6
|
|
@ -7,48 +7,28 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace Elsa.Workflows.Middleware.Workflows;
|
||||
|
||||
/// <summary>
|
||||
/// Adds extension methods to <see cref="ExceptionHandlingMiddleware"/>.
|
||||
/// </summary>
|
||||
public static class EngineExceptionHandlingMiddlewareExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Installs the <see cref="ExceptionHandlingMiddleware"/> component in the activity execution pipeline.
|
||||
/// </summary>
|
||||
public static IWorkflowExecutionPipelineBuilder UseEngineExceptionHandling(this IWorkflowExecutionPipelineBuilder pipelineBuilder) => pipelineBuilder.UseMiddleware<EngineExceptionHandlingMiddleware>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Catches any exceptions thrown by downstream components and transitions the workflow into the faulted state.
|
||||
/// </summary>
|
||||
public class EngineExceptionHandlingMiddleware : IWorkflowExecutionMiddleware
|
||||
public class EngineExceptionHandlingMiddleware(WorkflowMiddlewareDelegate next, ISystemClock systemClock, ILogger<EngineExceptionHandlingMiddleware> logger) : IWorkflowExecutionMiddleware
|
||||
{
|
||||
private readonly WorkflowMiddlewareDelegate _next;
|
||||
private readonly ISystemClock _systemClock;
|
||||
private readonly ILogger<ExceptionHandlingMiddleware> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public EngineExceptionHandlingMiddleware(WorkflowMiddlewareDelegate next, ISystemClock systemClock, ILogger<ExceptionHandlingMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
_systemClock = systemClock;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask InvokeAsync(WorkflowExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
await next(context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogWarning(e, "An exception was caught from a downstream middleware component");
|
||||
logger.LogWarning(e, "An exception was caught from a downstream middleware component");
|
||||
var exceptionState = ExceptionState.FromException(e);
|
||||
var now = _systemClock.UtcNow;
|
||||
var now = systemClock.UtcNow;
|
||||
var activity = context.Workflow;
|
||||
var incident = new ActivityIncident(activity.Id, activity.Type, e.Message, exceptionState, now);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue