diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 98a37e29..ed5c0ddf 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -46,11 +46,12 @@ public partial class App : Application public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; // singletons - public static readonly Logger Logger = new(); public static readonly JsonManager Settings = new(); public static readonly JsonManager State = new(); public static readonly FastFlagManager FastFlags = new(); - public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); + + public static readonly Logger Logger = new(); + public static readonly HttpClient HttpClient = new(new HttpClientLoggingHandler(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All })); public static System.Windows.Forms.NotifyIcon Notification { get; private set; } = null!; diff --git a/Bloxstrap/HttpClientLoggingHandler.cs b/Bloxstrap/HttpClientLoggingHandler.cs new file mode 100644 index 00000000..ccf7bd28 --- /dev/null +++ b/Bloxstrap/HttpClientLoggingHandler.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Bloxstrap +{ + internal class HttpClientLoggingHandler : MessageProcessingHandler + { + public HttpClientLoggingHandler(HttpMessageHandler innerHandler) + : base(innerHandler) + { + } + + protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken) + { + App.Logger.WriteLine($"[HttpClientLoggingHandler::HttpRequestMessage] {request.Method} {request.RequestUri}"); + return request; + } + + protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellationToken) + { + App.Logger.WriteLine($"[HttpClientLoggingHandler::HttpResponseMessage] {(int)response.StatusCode} {response.ReasonPhrase} {response.RequestMessage!.RequestUri}"); + return response; + } + } +} diff --git a/Bloxstrap/RobloxDeployment.cs b/Bloxstrap/RobloxDeployment.cs index ed865c87..de784093 100644 --- a/Bloxstrap/RobloxDeployment.cs +++ b/Bloxstrap/RobloxDeployment.cs @@ -110,8 +110,6 @@ public static async Task GetInfo(string channel, bool timestamp = throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})"); } - App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Got JSON: {rawResponse}"); - ClientVersion clientVersion = JsonSerializer.Deserialize(rawResponse)!; // for preferences diff --git a/Bloxstrap/Utilities.cs b/Bloxstrap/Utilities.cs index 5cce944b..bed046f7 100644 --- a/Bloxstrap/Utilities.cs +++ b/Bloxstrap/Utilities.cs @@ -49,14 +49,12 @@ public static int GetProcessCount(string processName, bool log = true) { try { - App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Getting JSON from {url}!"); string json = await App.HttpClient.GetStringAsync(url); - App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Got JSON: {json}"); return JsonSerializer.Deserialize(json); } catch (Exception ex) { - App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Failed to deserialize JSON!"); + App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Failed to deserialize JSON for {url}!"); App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] {ex}"); return default; }