Thursday, April 30, 2009

How to write Custom Audit Entries in WSS3.0?

Last year i attend Ted's training on WSS3.0. He given all Lab and whitepapers which are published by him.I am reading one by one.
One article on Audit logging is awasome.
I would like to post the summary of the article.
Audit logs detailing events that track data such as which users viewed and updated records and documents, and when these events occurred.
Microsoft Windows SharePoint Services 3.0 (WSS 3.0) and Microsoft Office SharePoint Server 2007 (MOSS) provide support for auditing user access to pages, content, and documents, and includes auditable events such as viewing and updating.
While WSS provides the basic auditing mechanisms, MOSS adds value by supplying an administrative user interface that allows auditing at the site collection level. MOSS goes even further and enables auditing at the list or document library level, and control over what types of events should be recorded in the audit log. MOSS also provides a reporting function that uses Microsoft® Office Excel® workbooks to display and keep records of audit logs. Therefore, MOSS allows you to take advantage of the WSS auditing support without having to write any custom code.
// turn on auditing flags to a list
SPSite siteCollection = new SPSite("http://LitwareServer1");
SPWeb site = siteCollection.OpenWeb();
SPList list = site.Lists["Proposals"];
list.Audit.AuditFlags = SPAuditMaskType.View
SPAuditMaskType.Update
SPAuditMaskType.Delete;
list.Audit.Update();
The code is written to read the audit log of the current site collection by creating an SPAuditQuery object.
SPAuditQuery wssQuery = new SPAuditQuery(siteColl);
SPAuditEntryCollection auditCol = siteColl.Audit.GetEntries(wssQuery);

As you examine the implementation of the code that reads information from the WSS audit log, observe how it retrieves user names. The WSS audit log tracks user IDs but not user names. After you have obtained a user ID, you can retrieve the associated user name using the GetByID method on the SiteUser collection, which is exposed as a property of the top-level site. Make sure you use the SiteUsers collection; do not confuse this with the User collection, which does not provide the same results.
string GetUserNameById(int UserId, SPWeb site) {
return site.SiteUsers.GetByID(UserId).Name;
//return site.Users.GetByID(UserId).Name; - YOU CANNOT USE SPWeb.Users collection here

}

Writing custom audit entry
item.Audit.WriteAuditEvent(SPAuditEventType.Custom, "CustomViewAuditEvent", "");

2 comments:

Research Writer said...

Many institutions limit access to their online information. Making this information available will be an asset to all.
Custom Paper Writing

ADmin said...

In the event that you get to pick your particular subject, make it something you are essay editing intrigued by. Thusly the examination will end up being much simpler and your willingness will 'rub off' on your followers.