Click or drag to resize

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.

Access the controller event log

You can access the event log domain through the Controller property EventLog.

C#
private EventLog log = aController.EventLog;
VB
Private log As EventLog = aController.EventLog
Private log As EventLog = aController.EventLog
private EventLog log = aController.EventLog;
Access 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 method GetCategory or by using the Categories property, which is an array of all available categories.

VB
Dim Cat As EventLogCategory
Cat = Log.GetCategory(CategoryType.Program)

or

C#
EventLogCategory cat;
cat = log.GetCategory(CategoryType.Program);

or

VB
Cat = Log.Categories(4)

or

C#
cat = log.GetCategory[4];
Note Note

The EventLogCategory should be disposed of when it is no longer used.

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

C#
EventLogMessage msg = cat.Messages[1];
VB
Dim msg As EventLogMessage = Cat.Messages(1)

or

C#
foreach(EventLogMessage msg in cat.Messages)
{
this.textBox1.Text = msg.Title;
.....
}
VB
Dim msg As EventLogMessage
For Each msg In Cat.Messages
Me.textBox1.Text = msg.Title
.....
Next Item
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.

C#
private void log_MessageWritten(object sender, MessageWrittenEventArgs e)
{
EventLogMessage msg = e.Message;
}
VB
Private Sub Log_MessageWritten(sender As Object, e As MessageWrittenEventArgs) Handles Log.MessageWritten
Dim Msg As EventLogMessage = e.Message
End Sub
Note 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.