I have been asked this question before, and keep coming back to NotesTracker. You certainly can write your own C API code to do this, but I always like to use existing solutions before writing a new one. I have not used NotesTracker, but it seems to be the right tool for this job.
Here is some info posted on Notes.net by Tony Austin:
NotesTracker is an easy-to-use SDK for developers to quickly modify any database for detailed usage tracking and analysis.
As of Version 4, NotesTracker (as distributed) tracks database usage for user actions performed via Notes clients or Web browsers. Purchasers can tailor the code to do other things, such as track actions performed via agents. You could probably extend the code for some form of tracking of attachments and OLE objects (but this is not part of the standard toolkit as it's a rather specialized requirement).
NotesTracker has all sorts if tracking/analysis uses, and can even provide a dynamic feed from multiple databases into "Breaking News" or "What's New" embedded views for your intranet or Internet portal pages.
Furthermore, there's a FREEWARE Notes/Domino application: SDMS (a Simple Document Management System). This has full NotesTracker functionality built in, so you can use it productively and get a good feel for how NotesTracker would work in your other databases. Go to the SDMS download page.
By the way, I've assembled lots of useful links on the site. For example, http://www.asiapac.com.au/Links/NotesDomino.htm and many more links accessible from http://www.asiapac.com.au/UsefulLinks.htm.
This was first published in October 2003