How to change the level of AX info messages
Asked Answered
B

1

11

In Dynamics AX 2009 I am trying to determine the level of indentation of an info message. What I want is something similar to this:

Prefix
    Info1
    Info2
Prefix2
    Info3

I found this:

http://www.doens.be/2010/05/the-ax-infolog/

But don't want to use a loop, so I thought something like this might work:

setprefix("Prefix");    

{
    info("Info1");
    info("Info2");
}

setprefix("Prefix2");

{
    info("Info3");
}

But it doesn't. Is there a way to do this in x++, and what are the rules as to what indent level is currently active?

Bloem answered 12/7, 2011 at 13:23 Comment(0)
L
17

setPrefix in AX sets (adds) the prefix for the current execution scope, and when leaving the scope the prefix is automatically reset to the previous level. You can use getPrefix to check the current execution prefix.

2 hacks can help you recieve the expected result:

#1

static void TestJob(Args _args)
{
    void sub1()
    {
        setprefix("Prefix");
        info("Info1");
        info("Info2");
    }

    void sub2()
    {
        setprefix("Prefix2");
        info("Info3");
    }
    ;

    setPrefix("Main");
    sub1();
    sub2();
}

#2

static void TestJob(Args _args)
{
    setPrefix("Main");
    info("Prefix\tInfo1");
    info("Prefix\tInfo2");
    info("Prefix2\tInfo3");
}
Layout answered 12/7, 2011 at 15:41 Comment(2)
WOW Job #2 needs more attention. I didn't realize that a tab would actually force the next prefix level in some way. Great postAscending
Indeed Job #2 is awesome. I just tried it with multiple tabs and it creates multiple sublevels as needed.Chang

© 2022 - 2024 — McMap. All rights reserved.