2019-08-22 20:15:25 +00:00
|
|
|
|
using System;
|
2020-06-06 19:42:02 +00:00
|
|
|
|
using System.Threading;
|
2019-08-22 20:15:25 +00:00
|
|
|
|
using RestSharp;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Integration.Test.Client
|
|
|
|
|
{
|
|
|
|
|
public class LogsClient : ClientBase
|
|
|
|
|
{
|
|
|
|
|
public LogsClient(IRestClient restClient, string apiKey)
|
|
|
|
|
: base(restClient, apiKey, "log/file")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetLogFileLines(string filename)
|
|
|
|
|
{
|
2020-06-06 19:42:02 +00:00
|
|
|
|
var attempts = 10;
|
|
|
|
|
var attempt = 1;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var request = BuildRequest(filename);
|
|
|
|
|
var content = Execute(request, System.Net.HttpStatusCode.OK);
|
2019-08-22 20:15:25 +00:00
|
|
|
|
|
2020-06-06 19:42:02 +00:00
|
|
|
|
var lines = content.Split('\n');
|
|
|
|
|
lines = Array.ConvertAll(lines, s => s.TrimEnd('\r'));
|
|
|
|
|
Array.Resize(ref lines, lines.Length - 1);
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (attempt == attempts)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex, "Failed to get log lines");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2020-10-13 16:47:13 +00:00
|
|
|
|
|
2020-06-06 19:42:02 +00:00
|
|
|
|
_logger.Info(ex, "Failed to get log lines, attempt {0}/{1}", attempt, attempts);
|
|
|
|
|
Thread.Sleep(10);
|
|
|
|
|
attempt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-22 20:15:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-03 12:49:24 +00:00
|
|
|
|
}
|