I would like to keep a log of each page view for all users of my web application. After enough time has passed, I will then use that log to generate reports. I would like to have the logging mechanism be a bit flexible since I wouldn't need to log every http request.
An example use case is: A company signs up for my web app and allows 5 employees to use the application. I would like to report that 3 employees used the application in the last week. Or show that 4 employees used it between June and August of the current year.
I'm using asp.net mvc with sql server, if that makes a difference.
Is it just as simple as this? Create a sql table with the following columns: UserId, ControllerName, ActionName, ActionParameters, CreatedOn. Then create an ActionFilterAttribute that adds a record to the db for each action invoked.
Are there any pitfalls that I should worry about (other than a potentially large table size)?
Some of the pitfalls:
I would assume you would implement this in some type of custom AuthorizeAttribute so your not coding it on every controller but then it will be literally every request which would possibly be more than you actually need.
Have you considered using some type of IIS log parsing utility? It would have a lot of the info you need already.
Another option if you are willing to use JavaScript is that you could implement something along the lines of SiteCatalyst. You send a request using JavaScript from the client on page load to a controller action with the appropriate information in the url. eg:
www.example.com\AnalyticsController\Action\currentController\currentAction\userName
The advantage is that your logging is not executed in sequence with all your other operations and you can probably get it working by putting the AJAX call in the master page.
The downside is that it uses JavaScript which as pointed out could be disabled. It would also be really easy to spoof.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With