How to Send the Callstack to the Infolog

When troubleshooting a problem it is helpful to have the X++ callstack especially in scenarios where you cannot use the debugger in the environment or the issue happens sporadically. The following X++ code will retrieve the X++ callstack and send it to the infolog.  Add the example code to a method that is throwing an error or that you are otherwise concerned with.  Once you have finished troubleshooting the issue make sure you remove the example code from the existing X++ method.

container myCallStack;
int i;
str whatToWrite;

;

myCallStack = xSession::xppCallStack();
for(i=1; i<=conlen(myCallStack); i++)
{
    whatToWrite += conpeek(myCallStack, i);
}

info(whatToWrite);