Added further logging into the API's (debug logging)

pull/3049/head
tidusjar 6 years ago
parent e58263ec08
commit e0dab68c31

@ -72,6 +72,7 @@ namespace Ombi.Api
// do something with the response // do something with the response
var receivedString = await httpResponseMessage.Content.ReadAsStringAsync(); var receivedString = await httpResponseMessage.Content.ReadAsStringAsync();
LogDebugContent(receivedString);
if (request.ContentType == ContentType.Json) if (request.ContentType == ContentType.Json)
{ {
request.OnBeforeDeserialization?.Invoke(receivedString); request.OnBeforeDeserialization?.Invoke(receivedString);
@ -110,7 +111,7 @@ namespace Ombi.Api
} }
// do something with the response // do something with the response
var data = httpResponseMessage.Content; var data = httpResponseMessage.Content;
await LogDebugContent(httpResponseMessage);
return await data.ReadAsStringAsync(); return await data.ReadAsStringAsync();
} }
@ -122,6 +123,7 @@ namespace Ombi.Api
{ {
AddHeadersBody(request, httpRequestMessage); AddHeadersBody(request, httpRequestMessage);
var httpResponseMessage = await _client.SendAsync(httpRequestMessage); var httpResponseMessage = await _client.SendAsync(httpRequestMessage);
await LogDebugContent(httpResponseMessage);
if (!httpResponseMessage.IsSuccessStatusCode) if (!httpResponseMessage.IsSuccessStatusCode)
{ {
if (!request.IgnoreErrors) if (!request.IgnoreErrors)
@ -153,11 +155,24 @@ namespace Ombi.Api
{ {
Logger.LogError(LoggingEvents.Api, Logger.LogError(LoggingEvents.Api,
$"StatusCode: {httpResponseMessage.StatusCode}, Reason: {httpResponseMessage.ReasonPhrase}, RequestUri: {request.FullUri}"); $"StatusCode: {httpResponseMessage.StatusCode}, Reason: {httpResponseMessage.ReasonPhrase}, RequestUri: {request.FullUri}");
await LogDebugContent(httpResponseMessage);
}
private async Task LogDebugContent(HttpResponseMessage message)
{
if (Logger.IsEnabled(LogLevel.Debug)) if (Logger.IsEnabled(LogLevel.Debug))
{ {
var content = await httpResponseMessage.Content.ReadAsStringAsync(); var content = await message.Content.ReadAsStringAsync();
Logger.LogDebug(content); Logger.LogDebug(content);
} }
} }
private void LogDebugContent(string message)
{
if (Logger.IsEnabled(LogLevel.Debug))
{
Logger.LogDebug(message);
}
}
} }
} }

Loading…
Cancel
Save