hasancali_NetCoreAPI/Application/Common/Behaviours/LoggingBehaviour.cs
using System.Threading;
using System.Threading.Tasks;
using Application.Common.Interfaces;
using MediatR;
using MediatR.Pipeline;
using Microsoft.Extensions.Logging;

namespace Application.Common.Behaviours
{
    public class LoggingBehaviour<TRequest> 
        : IRequestPreProcessor<TRequest>
    {
        private readonly ILogger _logger;
        private readonly ICurrentUserService _currentUserService;

        public LoggingBehaviour(
            ILogger<TRequest> logger,
            ICurrentUserService currentUserService)
        {
            _logger = logger;
            _currentUserService = currentUserService;
        }


        public Task Process(
            TRequest request,
            CancellationToken cancellationToken)
        {
            var requestName = typeof(TRequest).Name;
            _logger.LogInformation(
                "Request: {Name} {@UserId} {@UserName} {@Request}",
                requestName,
                _currentUserService.Id,
                _currentUserService.Name,
                request);
            return Unit.Task;
        }
    }
}