To clear all infolog messages of a form just use infolog.cut() command. To get more details about this functionality you can read this article https://www.codecrib.com/2011/10/get-infolog-details-from-code.html
Ax – D365FO – How to : “The number of messages exceeds the limit of the Infolog (10000.)” message
If you're facing this warning message means you're exeeding the limit of infolog message. Default limit of Infolog messages is 10000, but you can change the value of MaxErrors macro in viewBuild() method of Info class (like shown below).