Logging independently of transaction scope by using a separate thread in Dynamics AX (deux)

 
Good evening
 
Michal Kupczyk from this thread on the Microsoft communities proposes a much better way to log independantly of transaction scope in Dynamics Ax than what I had originally proposed here. Instead of using a separate thread to log, is uses a UserConnection object.
 
In addition to being simpler, it also has the added value of working from within batches. Batches it seems don’t support multithreading.
 
void method()
{
    UserConnection conn = new UserConnection();

    yourLogTable = null;
    yourLogTable.setConnection(conn);

    ttsbegin;

    […]
    yourLogTable.Log = ‘This is tts-independent log’;
    yourLogTable.insert();

    if (some_error)
    {
        throw Error(‘Error in processing’);
    }

    ttscommit;
}

This entry was posted in Dynamics AX 2009. Bookmark the permalink.