-
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
Showing
3 changed files
with
9 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
using Elysian.Application.Interfaces; | ||
using MediatR; | ||
using MediatR.Pipeline; | ||
using Microsoft.Extensions.Logging; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Elysian.Application.Behaviors | ||
{ | ||
public class LoggingBehavior<TRequest>( | ||
public class LoggingBehavior<TRequest, TResponse>( | ||
ILogger<TRequest> logger, IClaimsPrincipalAccessor claimsPrincipalAccessor) | ||
: IRequestPreProcessor<TRequest> | ||
: IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : notnull | ||
{ | ||
private readonly ILogger _logger = logger; | ||
|
||
public async Task Process( | ||
TRequest request, | ||
CancellationToken cancellationToken) | ||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) | ||
{ | ||
var requestName = typeof(TRequest).Name; | ||
var user = claimsPrincipalAccessor.IsAuthenticated ? claimsPrincipalAccessor.UserId : "Anonymous"; | ||
|
||
_logger.LogInformation($"Application Request [User: {user}, Claims: {claimsPrincipalAccessor.Claims}, RequestName: {requestName}, Payload: {request}]"); | ||
await Task.FromResult(0); | ||
|
||
return await next(); | ||
} | ||
} | ||
} |
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