Tuesday, November 5, 2013

Exception logging

Log any exception for reference using the following code snippet.

Write a static method in the table "YourTableName".

public static void logExceptionData(InfologData _infologData, RefRecId yourTableRecId)
{
    str                                                    exceptionLogMsg;
    SysExceptionTable                           sysExceptionTable;
    SysInfoLogEnumerator                     sysInfoLogEnum;
    SysInfologMessageStruct                  infoMessageStruct;
    YourTableName yourTableName =  YourTableName ::findRecId(yourTableRecId,true);


    sysInfoLogEnum = SysInfoLogEnumerator::newData(_infologData);

    while(infoLogEnum.moveNext())
    {
        sysInfoMessageStruct  = SysInfologMessageStruct::construct(sysInfoLogEnum.currentMessage());
        exceptionLogMsg      += exceptionLogMsg? "\n" + infoMessageStruct.message() infoMessageStruct.message();
    }

    if (yourTableName.RecId)
    {
        ttsBegin;
        yourTableName.Log = exceptionMessage;
        yourTableName.LogDate = DateTimeUtil::utcNow();
        yourTableName.update();
        ttsCommit;
    }
}

After than, call this method as follows:

public void job ()
{
      AifInfoLog              aifInfoLog;
     Container                 infologCon;

    try
    {
        aifInfoLog = new AifInfoLog();
        ........................................
        ........................................
     }
     catch (Exception::Error)
    {
         infologCon= aifInfoLog.getInfoLogData();
        YourTableName::LogExceptionData(infologCon,this.parmYourTableRecId());
}

No comments:

Post a Comment