How to Send the Callstack to the Infolog in AX

By Leah Baker | February 4, 2013

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()));
}

Related Posts

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!