public AvailabilityLog AppendLog(int statusCode, string body, long responseTime) { if (AvailabilityLogs is null) { AvailabilityLogs = new List <AvailabilityLog>(); } var availabilityLog = new AvailabilityLog(DateTime.UtcNow, statusCode, body, responseTime); AvailabilityLogs.Add(availabilityLog); return(availabilityLog); }
private string GetStatus() { if (AvailabilityLogs is null) { return("ST_OK"); } if (AvailabilityLogs.Any() == false) { return("ST_OK"); } var newestRecord = AvailabilityLogs .OrderByDescending(e => e.CreatedAt) .First(); if (newestRecord.Body != ExpectedResponse || newestRecord.StatusCode != ExpectedStatusCode) { return("ST_ERROR"); } return("ST_OK"); }
public void ClearOutdatedLogs() { AvailabilityLogs.RemoveAll(e => DateTime.UtcNow >= e.CreatedAt.AddHours(LogLifetimeThresholdInHours)); }