private void EnforceErrorCountLimits(Organization organization) { if (organization.RetentionDays <= 0) { return; } Log.Info().Message("Enforcing error count limits for organization '{0}' with Id: '{1}'", organization.Name, organization.Id).Write(); try { // use the next higher plans retention days to enable us to upsell them BillingPlan nextPlan = BillingManager.Plans .Where(p => p.RetentionDays > organization.RetentionDays) .OrderByDescending(p => p.RetentionDays) .FirstOrDefault(); int retentionDays = organization.RetentionDays; if (nextPlan != null) { retentionDays = nextPlan.RetentionDays; } DateTime cutoff = DateTime.UtcNow.Date.AddDays(-retentionDays); _errorRepository.RemoveAllByDate(organization.Id, cutoff); } catch (Exception ex) { ex.ToExceptionless().MarkAsCritical().AddTags("Enforce Limits").AddObject(organization).Submit(); } }