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 8462aeea9f4..3ff9760b04e 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs @@ -78,6 +78,30 @@ public static void LogInformation(string details) } } + public static void LogError(string details) + { + if (null != logger) + { + logger.LogError(details); + } + else + { + System.Console.WriteLine(details); + } + } + + public static void LogError(int statusCode, Exception e) + { + var details = statusCode.ToString() + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace; + if (null != logger) + { + logger.LogError(details); + } + else + { + System.Console.WriteLine(details); + } + } /// /// Simple access to the logging api. Accepts a simple message (preformatted) and logs to debug logger. diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/HttpExceptionMiddleware.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/HttpExceptionMiddleware.cs index 86b3f04a512..8b567512be9 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/HttpExceptionMiddleware.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/HttpExceptionMiddleware.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Text.Json; @@ -62,7 +63,7 @@ public async Task Invoke(HttpContext context) Status = e.StatusCode.ToString() }; - DebugLogger.LogInformation(e.Message); + DebugLogger.LogError(e.Message); var body = JsonSerializer.Serialize(bodyObj); await context.Response.WriteAsync(body); @@ -79,6 +80,8 @@ public async Task Invoke(HttpContext context) response.Headers.Add("x-request-exception", "true"); response.Headers.Add("x-request-exception-error", Convert.ToBase64String(Encoding.UTF8.GetBytes(e.Message))); + DebugLogger.LogError(unexpectedStatusCode, e); + var bodyObj = new { Message = e.Message,