Wednesday, May 30, 2018

Write Event log entry for AOS runtime error in AX

public server static void writeEventLogEntry(str _message)
{
    System.Diagnostics.EventLog ev;
    System.Boolean sourceExists;
    System.Diagnostics.EventLogEntryType entryType;
    System.String msg;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();
    sourceExists = System.Diagnostics.EventLog::SourceExists('<AOS Runtime>', '<Computer Name>');
    if (sourceExists)
    {
        ev = new System.Diagnostics.EventLog('<Microsoft Dynamics AX AIF>',
'<Computer Name>',
'<AOS Runtime>');
        try
        {
            entryType = CLRInterop::parseClrEnum('System.Diagnostics.EventLogEntryType',
'<Error>');
            msg = _message;
            ev.WriteEntry(msg, entryType);
        }
        catch
        {
            exceptionTextFallThrough();
        }
        if (ev != null)
        {
            ev.Close();
        }
    }

    CodeAccessPermission::revertAssert();
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...