How to use LoggingBehaviour in Clean Architecture with .NET Core?

  .net-core, angular, architecture,, c#

I use CleanArchitecture for my .NET Core project with Angular and I am trying to use LoggingBehaviour class located on CleanArchitecture/src/Application/Common/Behaviours/ in that project template as shown below:

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

        public LoggingBehaviour(ILogger<TRequest> logger, ICurrentUserService currentUserService, 
            IIdentityService identityService)
            _logger = logger;
            _currentUserService = currentUserService;
            _identityService = identityService;

        public async Task Process(TRequest request, CancellationToken cancellationToken)
            var requestName = typeof(TRequest).Name;
            var userId = _currentUserService.UserId ?? string.Empty;
            string userName = string.Empty;

            if (!string.IsNullOrEmpty(userId))
                userName = await _identityService.GetUserNameAsync(userId);

            _logger.LogInformation("CleanArchitecture Request: {Name} {@UserId} {@UserName} {@Request}",
                requestName, userId, userName, request);

However, I have no idea about how to use it properly as there is not an example usage in that solution template. Could you please clarify me on how to use it properly according to this template example?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.