Writing in the event log from Dynamics AX

June 19, 2009 at 13:14
filed under Dynamics AX
Tagged , , ,

Writing to the event log in Windows using AX is very easy when you use the EventLog class from the System.Diagnostics namespace. The following job demonstrates how to use the EventLog class.

static void EventViewer(Args _args)
    System.Diagnostics.EventLog eventlog;
    #Define.LogSource("Dynamics AX")
    #Define.LogName("Dynamics AX Log")
    // check if the log already exists
        // create new log
        System.Diagnostics.EventLog::CreateEventSource(#LogSource, #LogName);

    eventlog = new System.Diagnostics.EventLog();

    // write info entry
    eventlog.WriteEntry("Just writing in the event viewer.");
    // write error entry
    eventlog.WriteEntry("Error! Please check the stack trace below. \n\n" +
        con2str(xSession::xppCallStack()), System.Diagnostics.EventLogEntryType::Error);
    // write warning entry
    eventlog.WriteEntry("Job finished." , System.Diagnostics.EventLogEntryType::Warning);
    info("Check the event viewer!");

A possible use for this is when monitoring batch jobs.
Tested using AX 2009, XP Pro.


RSS / trackback

  1. sushil

    clr object could not be invoked Error is being given but if i give an existing evnt viewer source entry it works.Final O/P info is printed but how to check whether entry is made or not. That is not visible

  2. Trackbacks