Sunday, July 3, 2016

Write into the System Event Viewer from Dynamics AX

Source Link :

https://chaituax.wordpress.com/2014/04/09/write-into-the-system-event-viewer-from-dynamics-ax/


static void writeEventLogEntry(Args _args)
{
    System.Diagnostics.EventLog eventlog;
#Define.LogSource(“Dynamics AX”)
  #Define.LogName(“Application”)    ;
// check if the log already exists
 if(!System.Diagnostics.EventLog::SourceExists(#LogSource))
{
// create new log        System.Diagnostics.EventLog::CreateEventSource(#LogSource, #LogName);
}
 eventlog = new System.Diagnostics.EventLog();    eventlog.set_Source(#LogSource);
// write info entry    eventlog.WriteEntry(“<Info>: 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);
}

static void WriteEventLog(Exception _exception, str _event)
 {
 str eventSource = “AX event”;
 str logType = “Application”;
 System.Diagnostics.EventLogEntryType eventLogEntryType;
 int eventCategory = 9999;
 ;
switch(_exception)
 {
 case Exception::Info:
 eventLogEntryType = System.Diagnostics.EventLogEntryType::Information;
 break;
 case Exception::Warning:
 eventLogEntryType = System.Diagnostics.EventLogEntryType::Warning;
 break;
default:
eventLogEntryType = System.Diagnostics.EventLogEntryType::Error;
 }
 if (!System.Diagnostics.EventLog::Exists(eventSource))
 {
 System.Diagnostics.EventLog::CreateEventSource(eventSource, logType);
 }
        System.Diagnostics.EventLog::WriteEntry(eventSource, _event, eventLogEntryType, eventCategory);
 }





static void EventViewer(Args _args)
{
     System.Diagnostics.EventLog eventlog;
     #Define.LogSource("Dynamics AX")
     #Define.LogName("Dynamics AX Log")
    
     ;
     // check if the log already exists
     if(!System.Diagnostics.EventLog::SourceExists(#LogSource))
     {
         // create new log
         System.Diagnostics.EventLog::CreateEventSource(#LogSource, #LogName);
     }
     eventlog = new System.Diagnostics.EventLog();
     eventlog.set_Source(#LogSource);
     // 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!");
}

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...