Question

Or there's a SP2010 Built-in service to access Audit data?

[UPDATE] Quick awnser, No, there's no way to access the SPAuditQuery from the SP JavaScript Class Library.

At the end I end up using a WCF Service, using all the guidance provided by @almostSharepointMaster, pulling the SPAuditQuery from javascript, just don't forget to elevate the context when querying from a WCF Service

using (ElevatedContext context = new ElevatedContext(SPContext.Current.Web, SPContext.Current.Site))
{
    context.Execute(delegate
    {
        SPList spList = context.Web.Lists[yourListId];
        SPListItem spItem = spList.GetItemById(yourItemId);

        SPAuditQuery auditQuery = new SPAuditQuery(context.Site);
        auditQuery.RestrictToListItem(spItem);

        SPAuditEntryCollection auditEntries = context.Site.Audit.GetEntries(auditQuery);

     });   
}

return auditEntries;
Was it helpful?

Solution

Its explained indepth here with images how to use SPAudit ;)

http://www.codeproject.com/Articles/431342/Auditing-A-Built-in-Feature-of-SharePoint

SPAudit and its members

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spaudit.aspx

members

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spaudit_members.aspx

This is taken from msdn that shows you how to access the log,

SPAuditQuery wssQuery = new SPAuditQuery(siteCollection);
wssQuery.RestrictToListItem(item);
SPAuditEntryCollection auditCol = site.Audit.GetEntries(wssQuery);

foreach (SPAuditEntry entry in auditCol) {
  // get info from audit log
}

This was taken from another thread posted below:

SPAuditQuery wssQuery = new SPAuditQuery(web.Site);
wssQuery.RestrictToUser(web.CurrentUser.ID);
wssQuery.AddEventRestriction(SPAuditEventType.View);
wssQuery.RestrictToList(SPContext.Current.List);

SPAuditEntryCollection auditCol;
auditCol = web.Site.Audit.GetEntries(wssQuery);

https://stackoverflow.com/questions/5158411/how-could-i-get-access-to-the-audit-log-for-non-admin-users

you could also use:

 SPAuditQuery wssQuery = 
  new SPAuditQuery(SPContext.Current.Site);

please also note that youll run into some restricons with amdmin right! as the last link states, take into condiseration the statment below from msdn also especialy the last part ;)

My solution to the restriction is using SPSecurity.RunwithElevatedPrivileges as a little work around :)

The fundamental scope of any query is always a site collection; but you can use the members of the class to restrict a query to particular date ranges, users, event types, lists, and list items.

This class is primarily used as a parameter to the GetEntries(SPAuditQuery) method.

You cannot use this class to query the SharePoint database for anything other than the records of audited events.

SPAutitQuery class

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spauditquery.aspx

EDIT

If you want to use a webservice you can by following the example, all you need to do is have this code:

SPSite oSiteCollection = (SPSite)properties.Feature.Parent;
SPAuditQuery oAuditQuery = new SPAuditQuery(oSiteCollection);
oAuditQuery.RestrictToListItem(item);
SPAuditEntryCollection collAuditEntries = oSiteCollection.Audit.GetEntries(oAuditQuery);

foreach (SPAuditEntry oAuditEntry in collAuditEntries) {
  // get info from audit log
}

obviously have a return method that returns the results :)

http://msdn.microsoft.com/en-us/library/ms457256.aspx

hope it helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top