Using Event Monitor for logging
Event Monitor allows central logging in the database, allowing any client to follow-up and possibly retrieve status of their events. Although Event Monitor can be used to log all kinds of information, the logging is mainly used for grouping the logging of background tasks.
Introduction
An overview of the steps necessary to insert the logging (of a background task) into Event Monitor is provided. To begin, a focus on the flow of the asynchronous processes is described.
- The synchronous part where all necessary information is collected. This information is sent as event data to the asynchronous part.
- The asynchronous part receives the event data and uses this to perform the background task
Synchronous part
Initialize the event
Before you can log anything into Event Monitor, you always have to initialize your event using StartEvent.
Log information
When the event is initialized, you can start logging information into the event using AddEventDetail.
Error handling
If the event is initialized and an exception occurs, the event must be closed before leaving the method. If the event is not closed, the event will remain
BUSYFirst log the exception and all necessary information about the exception into Event Monitor using AddEventDetail. Then close the event using EndEvent.
Asynchronous part
Get the unique identifier of the event
- Normally the event is initialized in the synchronous part and the asynchronous part gets an
EventId. Before starting to log information into Event Monitor, theEventIdmust be converted into theProgressIdusing the method GetProgressId. - If the event is not yet initialized, you can start the event in the asynchronous part using StartEvent.
- Normally the event is initialized in the synchronous part and the asynchronous part gets an
Log information
When you have the unique identifier of the event, you can add extra information to the event.
There are 2 methods available for logging information into Event Monitor:- AddEventDetail which can be used for logging extra information
- If you not only want to log information but you also want to update the progress information (current or maximum) , you can use AddEventDetailWithProgress . For performance reasons, you should NOT use this method if you don't want to update the progress information.
Close the event
At the end of the asynchronous part the event must be closed using EndEvent
Error handling
If the event is initialized and an exception occurs, the event must be closed before leaving the method. If the event is not closed, the event will remain
BUSY.First log the exception and all necessary information about the exception into Event Monitor using AddEventDetail. Then close the event using EndEvent.
- All methods in the
Event Monitor Web Servicesthrow an exception when an error occurs. If you don't want your (background) process to fail because the logging throws an error, you should make a wrapper method to catch and handle the exceptions of Event Monitor.