Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #101 #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ You can choose to use SQL instead by following this:

### Other Audit Log Configuration Options

Backups and record duration can be configured in the `zSCSAuditLog.config` file. It is recommended that you keep only what would be useful as due to the volume of data collected, these logs can get get large on a site with a high number of events if keeping logs for more than a week.
Backups and record duration can be configured in the `zSCSAuditLog.config` file.

* keepRecords: Number of days to keep audit log records
* keepBackups: Number of days to keep backup files (Lucene only)

#### Lucene:
It is recommended that you keep only what would be useful as due to the volume of data collected, these logs can get get large on a site with a high number of events if keeping logs for more than a week.

#### SQL:
If using SQL mode, a lot of data can be stored before performance is impacted. Consider setting `keepRecords` to 180 (keep 180 days of data).

Additional events can be tracked using additional onSaved nodes. Note that new registered events need to have a unique id assigned to it and while it’s not required a unique color would be preferable from a user experience standpoint.

Expand Down
28 changes: 23 additions & 5 deletions ScsAuditLog/Core/SqlAuditLog.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using Sidekick.AuditLog.Model;
using Sidekick.AuditLog.Model.Interface;
using Sidekick.Core.Services.Interface;
using Sitecore.Data.Items;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Linq;
using System.Dynamic;
using System.Linq;
using System.Text;
using Sidekick.AuditLog.Model;
using Sidekick.AuditLog.Model.Interface;
using Sidekick.Core.Services.Interface;
using Sitecore.Data.Items;
using System.Threading.Tasks;

namespace Sidekick.AuditLog.Core
{
Expand All @@ -28,6 +29,11 @@ public SqlAuditLog(int daysToKeepLog, int daysToKeepRecords, bool logAnonymousEv
_logDays = daysToKeepLog;
_recordDays = daysToKeepRecords;
_logAnonymousEvents = logAnonymousEvents;

Task.Run(() =>
{
CleanupOldData();
});
}

public IEnumerable<KeyValuePair<string, int>> AutoComplete(string text, string start, string end, List<object> eventTypes)
Expand Down Expand Up @@ -272,6 +278,18 @@ public int RebuildLogStatus()
return -1;
}

private void CleanupOldData()
{
using (var db = new SqlAuditLogDataContext())
{
var dateCutoff = DateTime.Now.AddDays(-_logDays);
db.ExecuteCommand(
"DELETE FROM [dbo].[AuditEntry] WHERE [TimeStamp] < {0}",
dateCutoff
);
}
}

private string BuildArrayQuery(IEnumerable<object> terms, string key, Dictionary<string, bool> databases)
{
if (key == "event") key = "EventId";
Expand Down
4 changes: 3 additions & 1 deletion ScsAuditLog/Pipelines/OnSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public override void Process(object sender, EventArgs e)
Field field = item.Fields[fieldChange.FieldID];
if (!field.Name.StartsWith("__") && fieldChange.OriginalValue != field.Value)
{
var originalValue = fieldChange.OriginalValue ?? string.Empty;
var newValue = field.Value ?? string.Empty;
flag = true;
sb.Append("<tr><td>");
sb.Append(Cleanse(field.Name));
sb.Append("</td><td>");
HtmlDiff.HtmlDiff diff = new HtmlDiff.HtmlDiff(HttpUtility.HtmlEncode(fieldChange.OriginalValue), HttpUtility.HtmlEncode(field.Value));
HtmlDiff.HtmlDiff diff = new HtmlDiff.HtmlDiff(HttpUtility.HtmlEncode(originalValue), HttpUtility.HtmlEncode(newValue));
sb.Append(diff.Build());
sb.Append("</td></tr>");
}
Expand Down