How to Send the Callstack to the Infolog in AX
By Becky Newell
When I worked for Microsoft I wrote a blog on how to send the X++ callstack in AX to the infolog. Here is that post: http://blogs.msdn.com/b/axsupport/archive/2010/08/02/how-to-send-the-callstack-to-the-infolog.aspx
Sending the callstack to the infolog is extremely helpful when troubleshooting an issue that happens sporadically or when you are in a production environment and cannot run the debugger.
However, in AX 2012 a lot of code is executed as IL code like posting sales orders, purchase orders or running any process in batch. When code is executed as IL code the steps listed in the blog above do not work and will throw exceptions. We therefore need a different approach for capturing the IL and/or X++ callstack. The code below shows you how to grab the callstack regardless of how the code is executed. Enjoy and happy programming!
System.Diagnostics.StackTrace myStackTrace = new System.Diagnostics.StackTrace(true);
System.Exception ex;
if (xSession::isCLRSession())
{
try
{
info(myStackTrace.ToString());
}
catch
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
info(ex.ToString());
}
}
}
}
else
{
info(con2Str(xSession::xppCallStack()));
}
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.