So you have a custom task importing, updating and/or removing thousands of items in your website. Everything works fine, but your Event Log and Recycle Bin are being flooded with data. A quick tip to help you create some ease in this ocean of data.
The quickest way is to disable everything. You can disable the logging to the Event Log in the Settings. You can also configure to not move objects to the Recycle bin.
If you have to temporarily disable logging this might be a good idea, however this will probably be a bit extreme in most common situations.
In this example I'll be working with a Custom Scheduled Task deleting and creating 1000 Products (SKUs), but this will also work for other Kentico Objects.
This simple custom Scheduled Task is divided in two blocks. First I get all excisting SKUs where the name is like "Kentico-" and delete them. Secondly I create 1000 new ones. Finally I return the number of altered items.
If you run this Scheduled Task and look at the Event log you see it's being flooded with delete and creation messages.
Also the Recycle bin is being filled with items. This is even worse since the Recycle bin doesn't have a max size limit that you can configure, such as you do have for the Event Log.
So what we would like is to temporarily disable this logging during this task, but all other events on the Site must continue using logging. If you look in the code you can't really find an override to use or not use logging.
Kentico has a solution for you. You can use the CMSActionContext located in the CMS.Base namespace.
In the following code you can see an "Improved" version of the Scheduled Task. I've created a few regions for the delete and create part. Added the CMSActionContext and set 2 variables.
And that's it! I insert only one entry to the Event log with the result. If really needed you could also include a line for every delete and create event into this 1 description.
No more flooded Event Log, Recycle bin. But you can also set the context to not create
- Staging tasks
- Web farm tasks
- sync objects for Continuous Integration
- Smart Search tasks
- and more!
Use intellisense in your code or see the API documentation on Kentico Devnet:
this was all done in Kentico 10
but this feature is available at least since Kentico 6