-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a69d04
commit e788eb7
Showing
4 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
VirtualMind.Application/Commom/Middlewares/UnhandledExceptionBehaviour.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtualMind.Application.Commom.Middlewares | ||
{ | ||
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
{ | ||
private readonly ILogger<TRequest> _logger; | ||
|
||
public UnhandledExceptionBehaviour(ILogger<TRequest> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) | ||
{ | ||
try | ||
{ | ||
return await next(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
var requestName = typeof(TRequest).Name; | ||
|
||
_logger.LogError(ex, "You got an error: Unhandled Exception for Request {Name} {@Request}", requestName, request); | ||
|
||
throw; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters