diff --git a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs
index b60fe8d23b3ee..ce4d809173347 100644
--- a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs
+++ b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs
@@ -414,22 +414,19 @@ public DiagnosticsHttpHandler(HttpMessageHandler messageHandler)
/// The http response message content.
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
- if (request.Content != null)
- {
- var requestContent = await request.Content.ReadAsStringAsync().ConfigureAwait(false);
- _logger.Trace($">> Body: {requestContent}");
- }
-
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
- if (!response.IsSuccessStatusCode)
+ if (!response.IsSuccessStatusCode && response.Content != null && request.Content != null)
{
+ var requestContent = await request.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
- _logger.Trace($"<< Body: {responseContent}");
+
+ _logger.Trace($">> Request Body: {requestContent}\n\n<< Response Body: {responseContent}");
}
return response;
}
+
}
}
}