diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs index a220c488236..e04061311b2 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs @@ -160,6 +160,7 @@ public static async Task LogRequestDetailsAsync(ILogger loggerInstance, HttpRequ } } + /// /// Helper function used to evaluate an incoming httprequest and non-destructively log some information about it using a provided logger instance. When not /// actually logging anything, this function is entirely passthrough. @@ -189,6 +190,19 @@ public static async Task LogRequestDetailsAsync(HttpRequest req) } } + /// + /// Helper function used to evaluate an incoming httprequest and non-destructively log some information about it using the non-DI logger instance. When not + /// actually logging anything, this function is entirely passthrough. + /// + /// The http request which needs to be detailed. + /// + public static async Task LogRequestDetailsAsync(HttpRequestMessage req) + { + if (CheckLogLevel(LogLevel.Debug)) + { + logger.LogDebug(await _generateLogLine(req)); + } + } /// /// Helper function used to evaluate an incoming httprequest and non-destructively log some information about it using the non-DI logger instance. When not @@ -204,6 +218,30 @@ public static async Task LogResponseDetailsAsync(HttpResponseMessage resp) } } + /// + /// Generate a line of data from an http request. This is non-destructive, which means it does not mess + /// with the request Body stream at all. + /// + /// + /// + private static async Task _generateLogLine(HttpRequestMessage req) + { + StringBuilder sb = new StringBuilder(); + string headers = string.Empty; + + using (MemoryStream ms = new MemoryStream()) + { + await JsonSerializer.SerializeAsync(ms, req.Headers); + headers = Encoding.UTF8.GetString(ms.ToArray()); + } + + sb.AppendLine("Request URI: [" + req.RequestUri+ "]"); + sb.AppendLine("Request method: [" + req.Method + "]"); + sb.AppendLine("Request headers: [" + headers + "]"); + + return sb.ToString(); + } + /// /// Generate a line of data from an http request. This is non-destructive, which means it does not mess /// with the request Body stream at all. diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index d4bd582198d..ddd07a7f191 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -198,6 +198,8 @@ public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incom var upstreamRequest = CreateUpstreamRequest(incomingRequest, CompressionUtilities.CompressBody(entry.Request.Body, entry.Request.Headers)); + await DebugLogger.LogRequestDetailsAsync(upstreamRequest); + HttpResponseMessage upstreamResponse = null; // The experience around Content-Length is a bit weird in .NET. We're using the .NET native HttpClient class to send our requests. This comes with