Wednesday, April 8, 2015

AX32 Tip - Redirecting infolog output to the console

For automation purposes, you may need to execute startup commands or jobs which write their output to the Infolog. By default, this information is not saved anywhere, but there is a way to access it.


Part 1 - Set up a trace listener in Ax32.exe.config

Add the following to the app config file if not already present, before the </configuration> closing tag:

  <system.diagnostics>
    <trace autoflush="true"/>
    <sources>
      <source name="Microsoft.Dynamics.Kernel.Client.DiagnosticLog-Infolog"
              switchValue="Information">
        <listeners>
          <add name="configConsoleListener"
               type="System.Diagnostics.ConsoleTraceListener"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

Now the Infolog will write its output to STDOUT and STDERR.

Info Class Gotcha

Adding a global handler to the info class proved to be troublesome. It worked in most situations, but code executed on the server wasn't outputting to the client IO handles. That was just one obstacle I ran into.

Part 2 - Capturing the output of Ax32.exe in the console - DOS

Here's a DOS command which will start the Ax32.exe client and pipe the STDOUT and STDERR streams to findstr, which in turn prints to the console. If called without the pipe operator, the command returns immediately and the output is lost.

"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe" -startupcmd=<your startup command> -aol=<your layer, ie. CUS or USR> -LazyClassLoading -LazyTableLoading -internal=NoModalBoxes 2>&1 | findstr /x .*


This is the only non-intrusive method I have discovered for receiving data from the infolog. The trace listener header text can be stripped off. This is a small price to pay for utilizing the built in functionality.

Part 3 - Capturing the output of Ax32.exe in the console - PowerShell

I have written a separate entry which explains how to capture output in Powershell 3.0.

http://daxgotchas.blogspot.com/2015/02/powershell-tip-reading-output-from-the-infolog.html


See this post: http://daxgotchas.blogspot.com/2015/02/powershell-tip-reading-output-from-the-infolog.html

STDIO Gotcha

If the STDERR or STDOUT buffers get full, the next call to infolog will block until the buffer can receive more output. For example, piping to the "more" command will cause the application to hang until the user presses spacebar after each screen of information. This can potentially slow down the process being executed if it writes a lot of output (thousands of lines) to the infolog.