2020-05-03 12:00:50 +01:00
|
|
|
using System.Linq;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web.Http
|
|
|
|
{
|
|
|
|
public class SimpleHTTPLogger : IHTTPLogger
|
|
|
|
{
|
2020-05-05 14:30:00 +01:00
|
|
|
private const string OnRequestFormat = "\n{0} {1} [{2}] {3}";
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
|
2020-05-03 12:00:50 +01:00
|
|
|
public void OnRequest(IRequest request)
|
|
|
|
{
|
2020-05-05 14:30:00 +01:00
|
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
|
2020-05-03 12:00:50 +01:00
|
|
|
string parameters = null;
|
|
|
|
if (request.Parameters != null)
|
|
|
|
{
|
|
|
|
parameters = string.Join(",", request.Parameters?.Select(kv => kv.Key + "=" + kv.Value).ToArray());
|
|
|
|
}
|
2020-05-05 14:30:00 +01:00
|
|
|
|
|
|
|
Console.WriteLine(OnRequestFormat, request.Method, request.Endpoint, parameters, request.Body);
|
2020-05-03 12:00:50 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 14:30:00 +01:00
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
|
2020-05-03 12:00:50 +01:00
|
|
|
public void OnResponse(IResponse response)
|
|
|
|
{
|
2020-05-05 14:30:00 +01:00
|
|
|
Ensure.ArgumentNotNull(response, nameof(response));
|
|
|
|
|
|
|
|
string body = response.Body?.ToString().Replace("\n", "", StringComparison.InvariantCulture);
|
2020-05-03 12:11:53 +01:00
|
|
|
body = body?.Substring(0, Math.Min(50, body?.Length ?? 0));
|
2020-05-03 12:00:50 +01:00
|
|
|
Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|