/// <summary> /// Handles the logging of asynchronous unary calls. /// </summary> /// <typeparam name="TRequest">The type of the request.</typeparam> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The request.</param> /// <param name="context">The context.</param> /// <param name="oldTask">The old task.</param> /// <param name="call">The call.</param> internal void HandleAsyncUnaryLogging <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, Task <TResponse> oldTask, AsyncUnaryCall <TResponse> call) where TRequest : class where TResponse : class { // Generating log entry is expensive, so let's do that only if the log source // has been configured to do so. RpcException exception = null; if (TraceUtilities.ShouldGenerateSummaryRequestLogs()) { exception = UnaryRpcInterceptor.ParseTaskException <TResponse>(oldTask.Exception); LogEntry logEntry = new LogEntry(logCustomizer) { Host = config.ServerUrl, Method = context.Method.FullName, RequestHeaders = context.Options.Headers, // includes the RequestId IsFailure = oldTask.IsFaulted, Exception = exception, CustomerId = GetCustomerId(request), ResponseHeaders = Merge(GetResponseHeader(call.ResponseHeadersAsync), call.GetTrailers()), Response = (oldTask.IsFaulted) ? default : oldTask.Result, }; WriteSummaryLogs(logEntry); } if (TraceUtilities.ShouldGenerateDetailedRequestLogs()) { LogEntry logEntry = new LogEntry(logCustomizer) { Host = config.ServerUrl, Method = context.Method.FullName, RequestHeaders = context.Options.Headers, Request = request, ResponseHeaders = Merge(GetResponseHeader(call.ResponseHeadersAsync), call.GetTrailers()), Response = (oldTask.IsFaulted) ? default : oldTask.Result, Exception = exception ?? UnaryRpcInterceptor.ParseTaskException <TResponse>( oldTask.Exception), IsFailure = oldTask.IsFaulted, CustomerId = GetCustomerId(request), PartialFailures = (oldTask.IsFaulted) ? "" : GetPartialFailures(oldTask.Result) }; WriteDetailedLogs(logEntry); } }