I can't see any limitation in the code - I have attached it in case it answers your question:
Private Sub ClearErrorLog(ByVal si As SessionInfo, retentionDays As Integer, stepThreshold As Integer, taskItem As TaskActivityItem, batchSize As Integer, clearLogUser As String, clearLogApplication As String, errorLogDescription As String)
Try
'Initialize the Task Activity update threshold
Dim updateTime As DateTime = DateTime.Now.AddMinutes(5)
'Calculate the date threshold to used for the delete criteria
Dim yearMonthDay As String = GetThresholdDate(si, retentionDays, stepThreshold)
'Make sure that we do not clear log items if this Step Threshold is less than the Threshold selected by the user
If (Not String.IsNullOrEmpty(yearMonthDay)) Then
Dim parameters As New List(Of DbParamInfo) From {
New DbParamInfo("@yearMonthDay", yearMonthDay),
New DbParamInfo("@clearLogUser", clearLogUser),
New DbParamInfo("@clearLogApplication", clearLogApplication),
New DbParamInfo("@errorLogDescription", errorLogDescription.Trim())
}
'Delete all log information older than the supplied date
Dim msg As New Text.StringBuilder
msg.Append($"Delete Error Log ({yearMonthDay}) ")
Using dbConnFW As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
Dim logCount As Long = 0
'Get count of errors that match this date criteria and store in logCount variable
Dim sqlErrorLog As String = "SELECT COUNT(*) AS ErrorCount
FROM ErrorLog
WHERE (ErrorTime < CONVERT(DATETIME, @yearMonthDay, 102))"
If clearLogUser <> "(All)" Then
sqlErrorLog &= " AND UserName = @clearLogUser"
End If
If clearLogApplication <> "(All)" Then
sqlErrorLog &= " AND AppName = @clearLogApplication"
End If
If Not String.IsNullOrWhiteSpace(errorLogDescription.Trim) Then
sqlErrorLog &= " AND Description LIKE '%' + @errorLogDescription + '%' "
End If
Using dt As DataTable = BRApi.Database.ExecuteSql(dbConnFW, sqlErrorLog, parameters, True)
logCount = CType(dt.Rows(0).Item(0), Long)
End Using
'Now delete all of the Error Log Entries one batch at a time
Dim sqlLogDelete As String = $"DELETE TOP ({batchSize})
FROM ErrorLog
WHERE (ErrorTime < CONVERT(DATETIME, @yearMonthDay, 102))"
If clearLogUser <> "(All)" Then
sqlLogDelete &= " AND UserName = @clearLogUser"
End If
If clearLogApplication <> "(All)" Then
sqlLogDelete &= " AND AppName = @clearLogApplication"
End If
If errorLogDescription.Trim <> "" Then
sqlLogDelete &= " AND Description LIKE '%' + @errorLogDescription + '%' "
End If
'Now keep executing and committing this statement until the records affected count = 0
Dim cumErrorDeleteCount As Long = 0
Dim rowsErrorDeleted As Long = 0
Dim pctComplete As Decimal = 0d
'Keep deleting as long as the number of rows is equal to the batch size
Do While cumErrorDeleteCount < logCount
'Delete rows, but limit to batch size
rowsErrorDeleted = DbSql.ExecuteActionQuery(dbConnFW, CommandType.Text, sqlLogDelete.ToString, parameters, True)
cumErrorDeleteCount += rowsErrorDeleted
'Update TaskActivityStatus
If taskItem IsNot Nothing Then
If DateTime.Now >= updateTime Then
'Reset the update time indicator
updateTime = DateTime.Now.AddMinutes(5)
'Update the task status
pctComplete = Math.Round(((cumErrorDeleteCount / logCount) * 100), 0)
UpdateTaskActivityStatus(si, taskItem, $"Deleted: ({cumErrorDeleteCount}) Errors Of ({logCount}) Total Errors", pctComplete, 100)
End If
End If
Loop
'Update task status for final delete (Set to 100%)
UpdateTaskActivityStatus(si, taskItem, "Deleting Error Log", 100, 100)
'Log the delete information
msg.Append($"Error Log Entries = {logCount}")
If logCount > 0 Then
BRApi.ErrorLog.LogMessage(si, msg.ToString)
End If
End Using
End If
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Sub