diff --git a/src/AzurePipelines.TestLogger/ApiClient.cs b/src/AzurePipelines.TestLogger/ApiClient.cs index 1b40b12..9bf9aa6 100644 --- a/src/AzurePipelines.TestLogger/ApiClient.cs +++ b/src/AzurePipelines.TestLogger/ApiClient.cs @@ -248,7 +248,7 @@ internal virtual async Task SendAsync(HttpMethod method, string endpoint if (Verbose) { - Console.WriteLine($"Request:\n{method} {requestUri}\n{body}\n\nResponse:\n{response.StatusCode}\n{responseBody}"); + Console.WriteLine($"Request:\n{method} {requestUri}\n{body.Indented()}\n\nResponse:\n{response.StatusCode}\n{responseBody.Indented()}\n"); } try diff --git a/src/AzurePipelines.TestLogger/Json/JsonExtensions.cs b/src/AzurePipelines.TestLogger/Json/JsonExtensions.cs index 3a6bb34..f5dbd58 100644 --- a/src/AzurePipelines.TestLogger/Json/JsonExtensions.cs +++ b/src/AzurePipelines.TestLogger/Json/JsonExtensions.cs @@ -83,5 +83,46 @@ private static string JsonEscape(string value) return sb.ToString(); } + + /// + /// Indent JSON string. + /// + /// The JSON string. + /// The indented JSON string. + public static string Indented(this string input) + { + int level = 0; + StringBuilder result = new StringBuilder(); + + for (int i = 0; i < input.Length; i++) + { + char c = input[i]; + + if (c == '{' || c == '[') + { + result.Append(c); + result.AppendLine(); + result.Append(new string(' ', ++level * 2)); + } + else if (c == '}' || c == ']') + { + result.AppendLine(); + result.Append(new string(' ', --level * 2)); + result.Append(c); + } + else if (c == ',') + { + result.Append(c); + result.AppendLine(); + result.Append(new string(' ', level * 2)); + } + else + { + result.Append(c); + } + } + + return result.ToString(); + } } }