/// <summary> /// Removes older values to keep DB size within configured size limit. /// </summary> /// <param name="daysToKeep">Records older than this number of days are removed.</param> private void CleanOldValuesFromStatisticsDatabase(int daysToKeep) { if (daysToKeep <= 0) { return; } var thresholdDate = _dateTime.UtcNow.Date.AddDays(-daysToKeep); try { _statisticsRepository.CleanOldValues(thresholdDate); HomeGenieService.LogDebug( Domains.HomeAutomation_HomeGenie, "Service.StatisticsLogger", "Cleaned old values from database.", "DayThreshold", thresholdDate.ToString("O") ); } catch (Exception ex) { HomeGenieService.LogError( Domains.HomeAutomation_HomeGenie, "Service.StatisticsLogger", "Error cleaning old stats from the database", "Exception.StackTrace", $"{ex.Message}: {ex.StackTrace}" ); } }