Monday, June 22, 2009

Read Sharepoint Audit log reports

Share/Save/Bookmark

The audit log data enabled for a site collection can be read programmatically as follows:

SPSite siteCollection = SPContext.Current.Site;
SPAuditQuery wssQuery = new SPAuditQuery(siteCollection);
SPAuditEntryCollection auditCol;
auditCol = siteCollection.Audit.GetEntries(wssQuery);
// enumerate through audit log and read entries
foreach (SPAuditEntry entry in auditCol) {
    // inspect entry
}

Reading the log data can be a performance issue if all the entries are looped, so restrict the entries to either a list,listitem or a user using methods RestrictToList or ResstrictToListItem, RestrictToUser. SetRangeStart and SetRangeEnd methods on SPAuditQuery class can be used to get the logs for a limited period.


Subscribe

No comments:

Post a Comment