The EventManager.LogUserEvent method allows you to create user log Event objects. You can associate your custom Event with any managed entity. User log events are useful for marking actions or status associated with the objects your application deals with.
The following steps show how to create a user log Event.
Procedure
- Obtain the managed object reference to the EventManager.
..
ManagedObjectReference _svcRef = new ManagedObjectReference();
ServiceContent _sic = my_conn.retrieveServiceContent(_svcRef);
ManagedObjectReference eMgrRef = _sic.getEventManager();
...
- Obtain the managed object reference to the entity with which you are associating the Event.
For example, suppose you have a reference to a virtual machine (myVMRef
) and you want to log a message to record the fact that a virus check completed. You want to use myVMRef
as a parameter to the LogUserEvent
method in the next step.
- Call the
LogUserEvent
method, passing in the EventManager
and the Event
reference and a string consisting of the Event message for the msg parameter of the operation.
LogUserEvent(eMgrRef, myVMRef, "Completed virus check at 1:05 AM on Sunday December 21.");
Results
User-defined Event objects display in the vSphere Client among the other events on the system, with the prefix User logged event: followed by the text submitted in your msg parameter. In other client applications, such as in the console-based Event sample applications, custom events display as com.vmware.vim.GeneralUserEvent
objects.