/// <summary> /// Ages and prunes the log based on the System.MaxLogEntries and System.MaxLogDays AppConfigs /// </summary> private void Age() { var currentErrors = DB.GetSqlN("select count(*) as N from aspdnsf_SysLog"); var earliestDayToKeep = DateTime.Now.AddDays((MaxLogDays * -1)); DB.ExecuteSQL(string.Format("delete from aspdnsf_syslog where createdon < {0}", DB.SQuote(Localization.DateStringForDB(earliestDayToKeep)))); //Make space for new entries var entriesToDelete = currentErrors - MaxLogEntries; if (entriesToDelete > 0) { DB.ExecuteSQL(string.Format("delete from aspdnsf_syslog where SysLogID in (select top {0} SysLogID from aspdnsf_syslog order by createdon)", entriesToDelete + 5)); } }