I would like to use the security audit log report of a site collection, and evaluate the entries e.g. each hour. The focuss lays on actions/events performed on the access rights on the site. Which users are added, deleted, SP groups created, removed etc. This info will be written to a custom list.
Following code can be used to retrieve the events:
SPAuditQuery query = new SPAuditQuery(site);
query.AddEventTrstriction(SPAuditEventType.SecGroupCreate);
query.SetRangeStart(DateTime.Now.AddHours(-1);
SPAuditEntryCollection auditCol = site.Audit.GetEntries(wssQuery);
foreach(SPAuditEntry entry in auditCol)
{
// Do something with the entries
}
- When I execute this code every hour with e.g. a timer job how can I make sure not to miss entries which fall just on the hour, and are not picked up the next time the timer job is running?
- It's probably advisable to clean up this log file on a regular base using (SPAudit.DeleteEntries)?
- Maybe both points can be combined in one solution e.g. Take the timestamp of the last AuditEntry and delete all entries before this.