Event log domain
Overview
Event log messages may contain information about controller status, RAPID execution, the running processes of the controller, and so on.
Using the SDK it is possible to either read messages in the queue or to use an event handler that will receive a copy of each new log message. An event log message contains queue type, event type, event time, event title and message.
Accessing the controller event log
You can access the event log domain through the Controller property EventLog.
private EventLog log = aController.EventLog;
Accessing event log categories
All event log messages are organized into categories. To search for an individual message you have to know what category
it belongs to. The enumeration type, CategoryType, defines all available categories. You can get a category either by
using the GetCategory method or by using the Categories property, which is an array of all available categories.
EventLogCategory cat;
cat = log.GetCategory(CategoryType.Program);
or
cat = log.GetCategory[4];
Note
The EventLogCategory should be disposed of when it is no longer used.
Accessing event log messages
To access a message you use the Messages property of the Category object. A collection of messages is returned.
The collection implements the ICollection and IEnumerable interfaces , which means you can use the common operations
for collections. Access is done either using an index or by iterating using foreach.
EventLogMessage msg = cat.Messages[1];
or
foreach (EventLogMessage emsg in cat.Messages)
{
this.textBox1.Text = emsg.Title;
.......
}
MessageWritten event
It is possible to add an event handler that is notified when a new messages is written to the controller event log.
This is done by subscribing to the EventLog event MessageWritten.
The event argument is of type MessageWrittenEventArgs and has a Message property, which holds the latest
event log message.
private void log_MessageWritten(object sender, MessageWrittenEventArgs e)
{
EventLogMessage msg = e.Message;
}
Note
If the application user interface needs to be updated as a result of the event, you must delegate this job to the
GUI thread using the Invoke method. For more information and code samples,
see Controller events and threads.
Tip
Find out more about the EventLogDomain in the API Reference help.