Showing posts with label mongodb. Show all posts
Showing posts with label mongodb. Show all posts

Friday, August 23, 2024

Sitecore Custom Audit Logs Generation & move into NoSQL MongoDB Part - 2

Hi All,

As I said in my last blog post, we store our own audit logs in NoSQL MongoDB. I resumed my inquiry and created the code that appears below:

MongoExportUtil.cs

 

I tried that code first with some sample files, and it worked well. However, when I tried it with actual log files, I ran into trouble once more. This function threw an error while reading the current log file because it was being utilized by the Sitecore instance, which means the file is still alive. I therefore approach this differently. I developed a PowerShell script that can transfer and relocate all files from one location—the custom audit logs location—to another. Next, I carry out the mongoexport task, which goes off without a hitch, but hold on. We may lose some content because we are still adding audit logs, even though I duplicated the active audit log file. Therefore, the response is no, you shouldn't be concerned. If we repeat the procedure in the future, it will retrieve the updated data and update the particular record rather than creating a new one because it is updating based on the file name. Currently, it will copy the information and export it to MongoDB. An existing file will update the current record in the MongoDB record if there are any content updates.

Here below the PowerShell code:

Move Audit Logs.ps1

Final Config file:

z.Audit.config

Everything is now prepared, but how do we operate those things? In order to create custom buttons in Sitecore, I followed the blogs below: one to launch a PowerShell script that transfers log files between folders, and another to export text files (.txt) into MongoDB and remove the log files from the system because we don't want to keep the text file after exporting it to MongoDB. We can also solve the space problem by doing this.






You can follow the blogs below to create buttons; let me know if you run into any difficulties.

https://community.sitecore.com/community/en?id=community_blog&sys_id=71e267211bc370d0b8954371b24bcbdb

https://www.youtube.com/watch?v=r94VxfuGlyM


Reference code: https://github.com/gaurarun777/CustomAuditLogs/tree/main

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.


Monday, June 17, 2024

Sitecore Custom Audit Logs Generation & move into NoSQL MongoDB Part - 1

 Hi All,

After talking with my senior recently, we came to the conclusion that, while modifications are recorded in Sitecore logs, we do not have access to all audit log details, which presents a common issue across nearly all projects. Because there are so many other entries, it is quite difficult to determine that. In addition, we can store data in SQL, although doing so may eventually cause storage problems due to the database's excessive growth in size, and freetext search is not supported.

Thus, we made the decision to address and attempt to resolve that issue. We separated it into two sections for that:

Part 1: To start, we keep audit logs in a unique folder containing only the audit logs. This way, we can locate all audit-related items in one location and potentially mitigate the problem.

 

Part 2: All custom log data can be transferred to the NoSQL database MongoDB, allowing for cloud storage and more convenient detailed searches for changes to individual items.

I so began my research for Part 1. I broke up my work into the following steps:

 

1. Custom logs must be made in a designated folder.

2. Include audit-related entries.

I really appreciated the blogs listed below during my investigation. Kindly peruse those blogs, as they will offer you a glimpse of my intended actions.

https://www.sitecorefundamentals.com/a-complete-code-sample-for-creating-your-own-custom-sitecore-log

https://sitecore.stackexchange.com/questions/2966/logging-changes-in-sitecore-8-1-made-by-content-authors

I modified it to meet our demands, and the result is our unique code, which is below:

Audit.cs

z.AuditInitial.config

This code functioned as intended and began generating bespoke audit logs after the corresponding dll was deployed into the website bin folder.

However, since our ultimate objective is to store in NoSQL MongoDB rather than txt files, we are aware that it will generate an excessive number of files on disk, potentially leading to a storage problem.

In the next part, we will explain how we can write custom code to move these audit logs to MongoDB.

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.