You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/src/NzbDrone.Integration.Test/Client/LogsClient.cs

44 lines
1.3 KiB

using System;
using System.Threading;
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)
{
var attempts = 10;
var attempt = 1;
while (true)
{
try
{
var request = BuildRequest(filename);
var content = Execute(request, System.Net.HttpStatusCode.OK);
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;
}
_logger.Info(ex, "Failed to get log lines, attempt {0}/{1}", attempt, attempts);
Thread.Sleep(10);
attempt++;
}
}
}
}
}