Pages

Monday, October 18, 2010

SharePoint Auditing – Behind Screen and Remedy



 Hi,
from past few days I was on my way (as usual) and exploring SharePoint Server 2007 Features and so came across Auditing.
as name suggests , Auditing in MOSS 2007 is basically keeping an eye over your target users actions. what I mean is you can audit the events like what end users has viewed , downloaded , checked in , checked out from your site. and more granularly this can be done at the Item Level and so you called ItemLevelAuditing in MOSS 2007. you can have a look at this link for primary idea how and what Auditing and reporting is done.
so I came to know that , the Audited data gets saved in the Content db of the site collection so I headed forward and opened SQL Server Management Studio. there you can see the db Table Name : AuditData
what was surprising me that If one configures MOSS to audit all the OOB supported events then this might blot up the size of content db and can cause some trouble for public facing sites where you don't know how many end users you going to have for your site
when you open AuditData table and try to see some entries then SharePoint adds the event types and item types in some columns as numbers
I opened up faithful buddy reflector to see what those really are and here you can find those
Item Types
    Document = 1,
    Folder = 5,
    List = 4,
    ListItem = 3,
    Site = 7,
    Web = 6
now, suppose each audit entry requires space appx 64Kb of size per request then supposing 10000 users per day, so at the end of the day content db size only for AuditData table will be at least 64000KB(64MB) which is quite large.
there need to be something to have control over this one : and Microsoft has provided a remedy
there is something called as TrimAuditLogs. this is a stsadm operation and gives control to farm administrators to maintain the audit entries. administrators can run this command and trim the audit logs older than provided date
stsadm -o trimauditlog –date 20080704 –databasename WSSContent123456 
Note that : This operation is available after the Infrastructure Update for Microsoft Office Servers is installed.
so what If you don't have installed the required update?
nothing to worry .. developer can always find a way .. :)
Microsoft’s SharePoint Server object model provides number of APIs where you can do the stuff as you want
here is something small what I tried to delete all the old audit log entries in the db


try
{
      using (SPSite site = new SPSite("http://yoursite
"))
       {
            SPAudit auditE = site.Audit;
            auditE.DeleteEntries(DateTime.Now.AddMilliseconds(1));    //Microsoft Recommended
            Console.WriteLine("Entries Deleted");
       }
}
 catch (Exception ex)
  {
       Console.WriteLine(ex.Message);
   }
 Note that : SPAudit.DeleteEntries is a audit event so delete Audit Log will be written in db even If you delete all entries and this entry will not be deleted

you can play further with these APIs and have fun :)
Refn: here

No comments:

Post a Comment