Sitecore hooks provide you with an interface to invoke custom logic on system initialization before any HTTP web request is served. You can use hooks to subscribe to events dynamically, configure memory and health monitoring, switch MediaProviders and LinkProviders, interpret URLs, and much more.
In this recipe, you will learn how to use hooks to subscribe events to prepare an audit trail of different item operations such as create, delete, move, and others. You will also learn how to override MediaProvider using hooks.
We will first create an event handler class where we will create some event handling methods:
In the
SitecoreCookbook
project, create an event handlerAuditTrailEventHandler
class in theHandlers
folder, and create aWriteLogs
property in it:public bool WriteLogs { get; set; }
Create the
OnItemCreated()
andOnItemDeleted()
event methods as follows:public void OnItemCreated(object sender, EventArgs...