示例#1
0
        /// <summary>
        /// Execute log
        /// </summary>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The response</returns>
        public async Task Execute(CancellationToken cancellationToken)
        {
            bool isInfoEnabled = _logger.IsInfoEnabled;

            if (isInfoEnabled == true)
            {
                _logger.InfoFormat("Executing {0}", typeof(T).Name);
            }

            await _handler
            .Execute(cancellationToken)
            .ConfigureAwait(Await.Default);

            if (isInfoEnabled == true)
            {
                _logger.InfoFormat("Executed {0}", typeof(T).Name);
            }
        }
示例#2
0
        /// <summary>
        /// Logs upload has started and continues with uploading
        /// </summary>
        /// <param name="command">The command</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Upload continues</returns>
        public Task <IUploadResult> Upload(TCommand command, CancellationToken cancellationToken)
        {
            Argument.NotNull(command, nameof(command));

            if (_logger.IsInfoEnabled == true)
            {
                _logger.InfoFormat("Uploading {0}", command.Path);
            }

            return(_uploader.Upload(command, cancellationToken));
        }
示例#3
0
        /// <summary>
        /// Log and execute request
        /// </summary>
        /// <param name="request">The request</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The response</returns>
        public async Task <ApiResponse <TResponse> > Execute(ApiRequest <TRequest> request, CancellationToken cancellationToken)
        {
            Argument.NotNull(request, nameof(request));

            bool isInfoEnabled = _logger.IsInfoEnabled;

            if (isInfoEnabled == true)
            {
                _logger.InfoFormat("API request {0} {1}{2} {3}",
                                   request.Context.Method,
                                   request.Context.EndPoint,
                                   request.Context.Path,
                                   request.Context.Query);
            }

            var response = await _apiClient
                           .Execute(request, cancellationToken)
                           .ConfigureAwait(Await.Default);

            if (isInfoEnabled == true)
            {
                if (response.IsSuccessful == true)
                {
                    _logger.InfoFormat("API response Status: {0}, HttpStatusCode: {1}, RequestId: {2}",
                                       response.ResponseStatus,
                                       response.StatusCode,
                                       response.Headers.RequestId);
                }
                else
                {
                    _logger.InfoFormat("API response Status: {0}, HttpStatusCode: {1}, RequestId: {2}, Content: {3}",
                                       response.ResponseStatus,
                                       response.StatusCode,
                                       response.Headers.RequestId,
                                       response.Content);
                }
            }

            return(response);
        }