Loop through infolog in AX 2012 through code
In 2 methods we can loop through infolog messages and read the data about them
1)
The infolog class has a "copy" and a "cut" method that return the
contents of the infolog, in container form. The elements in the
container are containers themselves, each one corresponding to a line in
the infolog. So you get the container, loop over it, and for each
iteration you can grab the sub-container and extract the details like
the exception type, action class, helptext, etc.
static void InfologParse(Args _args)
{
container infologCon, infoline;
Exception exception;
int i;
str message;
str helpURL;
ClassName actionClassName;
container actionClassOptions;
;
// Put test data in infolog
setPrefix("First Prefix");
error("test error");
warning("test warning");
setPrefix("One more level");
info("infolog!");
// Get the infolog data and clear the messages (cut)
infologCon = infolog.cut();
for(i=1; i<=conLen(infologCon); i++)
{
infoline = conPeek(infologCon, i);
exception = conPeek(infoline, 1);
message = conPeek(infoline, 2);
helpURL = conLen(infoline) > 2 ? conPeek(infoline, 3) : '';
if(conLen(infoline) > 3 && conPeek(infoline, 4))
{
actionClassName = classId2Name(conPeek(infoline, 4));
actionClassOptions = conPeek(infoline, 5);
}
info(strFmt("Type: %1; Prefix: %2; Message: %3",
exception,
// replace the \t by / so we can see all prefixes
strReplace(message, '\t', '/'),
// copy the message from the last occurance of the \t to the end
subStr(message,
strScan(message, '\t',
strLen(message),
-strLen(message)) + 1,
strLen(message))));
}
}
2)
SysInfologEnumerator enumerator;
SysInfologMessageStruct msgStruct;
Exception exception;
enumerator = SysInfologEnumerator::newData(infolog.cut());
while (enumerator.moveNext())
{
msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
exception = enumerator.currentException();
info(strFmt("Type: %1; Prefix: %2; Message: %3",
exception,
msgStruct.preFixTextElement(1),
msgStruct.message()));
}
infolog.num([exception _exception]) --> this method returns number of infolog lines
of the exception type. If no exception type is passed it number the total number of
infolog lines
No comments:
Post a Comment