Sitecore provides many ways to integrate own logic while executing specific actions. One of those ways is event handler.
1. Default Event Handler
Sitecore have per default some events which are defined in Sitecore.config configuration file.
It is possible to catch those events and embed some methods within own created classes.
To achieve this, we need first to define which events need to be catched. As you can see some actions are defined with two different events. For example when the user delete an item, two events will be „fired“. First, the Event (item:deleting) will be occured while the item is deleting. Second, the event (item:deleted) will be occured after the item is deleted.
2. Create own event handler
In this block we will try to write something in log file after saving an item. We will catch the event (item:saved) and write the message „The ItemSavedEvent has been catched“ in log file. (item:saved) will occures after the item has been saved.
In the first step we will create the logic which will be affected after the (item:saved) event has been fired. The logic will be implemented within the new implemented class „ItemSavedHandler“. This class contains the method „OnItemSaved“.
As you can see, the function will log the message „The ItemSavedEvent has been catched“ as info in log file.
In the next step we will register this handler in Sitecore, there is two ways to register an own implemented event handler.
You can either add a handler to the specific event section in sitecore.config configuration file.
Or, subscribe the event handler at runtime using „Event.Subscribe“
Now, every time an item is saved, the message „The ItemSavedEvent has been catched“ will be logged.