开发者

Enabling SPAudit automatically for new files in list

I'm working with the Audit framework in MOSS 2007, and I've programatically enabled Auditing for 2 specific lists in a bunch of sites in a site collection(meaning 开发者_如何学运维the sites all have their own two lists). I've only enabled the update mask, as I only want to know when something's been changed or added.

However, I'm only able to log when something's been added, with my current setup. To allow for seeing changes to the list items, I'm aware that the list item itself has to have auditing enabled. But when adding a new item to the list, how do I automatically enable Auditing for the item? If possible, I'd prefer to avoid creating an event receiver to accomplish this.

*EDIT

The code I use to enable auditing looks something like this:

foreach (SPSite site in webApp.Sites) {
    foreach (SPWeb website in site.AllWebs) {
       website.Lists["MyList"].Audit.AuditFlags = SPAuditMaskType.Update;
       website.Lists["MyList"].Audit.Update();
    }
}

And to read it:

SPUserToken sysAdmin = website.Site.SystemAccount.UserToken;
using (SPSite elevatedSite = new SPSite(website.Site.ID,sysAdmin)) {
    using (SPWeb elevatedWeb = elevatedSite.OpenWeb(website.ID)) {
        SPAuditQuery auditQuery = new SPAuditQuery(elevatedSite);
        auditQuery.SetRangeStart(myDatetime);
        auditQuery.RestrictToList(elevatedWeb.Lists["MyList"]);
        listChanges = elevatedWeb.Lists["MyList"].Audit.GetEntries(auditQuery);
    }
}

I realize I'm restricting to list here, but when I didn't I got changes from other lists on the site as well. Even though logically I'd assume I only got the changes from the list I called "GetEntries" on...

Thanks


If the library has auditing enabled, then new items will be audited. I'm not aware of any document-specific auditing


A little late in replying to this, but here is some additional information in case others find this post.

It is possible to track the auditing events at the document level. This link explains how it can be done. They use an event handler to make it work. I know you mention you do not want to do it this way, but this is what is needed to automatically track document events. Setting the audit mask type on the document library appears to only track the DL events, not the individual items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜