Example #1
0
        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);
        }
Example #2
0
        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");
        }
Example #3
0
 public void ClearOutdatedLogs()
 {
     AvailabilityLogs.RemoveAll(e => DateTime.UtcNow >= e.CreatedAt.AddHours(LogLifetimeThresholdInHours));
 }