public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { var requestName = typeof(TRequest).Name; if (requestName == "PushRequestCommand") { return(await next()); } _timer.Start(); var response = await next(); _timer.Stop(); var elapsedMilliseconds = _timer.ElapsedMilliseconds; // internal log if logger take more than if (elapsedMilliseconds > 500) { var userId = _currentUserService.SystemCode ?? string.Empty; _logger.LogWarning("ASyncFramework.publisher Long Running Request:- RequestName {CreationDate} {Name} ({ElapsedMilliseconds} milliseconds) {@UserId} {@Request} {ReferenceNumber}", DateTime.Now, requestName, elapsedMilliseconds, userId, request, _referenceNumberService.ReferenceNumber); } return(response); }
public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { try { return(await next()); } catch (ValidationException) { _logger.LogWarning("{Status} {ReferenceNumber}", MessageLifeCycle.ValidationError, _referenceNumberService.ReferenceNumber); throw; } catch (Exception ex) { _logger.LogError(ex, MessageLifeCycle.ExceptoinWhenProcessNewRequest, _referenceNumberService.ReferenceNumber); throw; } }