1
0
mirror of synced 2024-12-19 01:35:53 +01:00
GC-local-server-rewrite/Application/Common/Behaviours/LoggingBehaviour.cs
2023-02-09 17:25:42 +08:00

24 lines
691 B
C#

using MediatR.Pipeline;
using Microsoft.Extensions.Logging;
namespace Application.Common.Behaviours;
public class LoggingBehaviour<TRequest> : IRequestPreProcessor<TRequest> where TRequest : notnull
{
private readonly ILogger<TRequest> logger;
// ReSharper disable once ContextualLoggerProblem
public LoggingBehaviour(ILogger<TRequest> logger)
{
this.logger = logger;
}
public Task Process(TRequest request, CancellationToken cancellationToken)
{
var requestName = typeof(TRequest).Name;
logger.LogInformation("Received request: {RequestName}, content: {Request}", requestName, request);
return Task.CompletedTask;
}
}