Writing to the Windows event log from within Dynamics AX.

The workflow runtime in AX 2009 will log any error it encounters to the Windows event log. We can log to the event log using .Net classes. The System.Diagnostics.EventLog class provides methods to do this.

To create an event log instance, we write the following line of code

ev = new System.Diagnostics.EventLog("Application");
ev.set_Source("Dynamics Server 01");


Here Application is the log we want to write into and Dynamics Server 01 is the source of the message.



You write a message to the log using the following line

ev.WriteEntry(msg, entryType);


In the above line, msg is the message you want to output and entryType is an enum value of type System.Diagnostics.EventLogEntryType which can be a warning, error or Information.

You can download the job for this from here.

Comments

Popular posts from this blog

How to add empty ranges in query

Get selected records in Dynamics AX 2012

The field with ID '0' does not exist in table - Cause and resolution.