Roger Lipscombe
Roger Lipscombe

Reputation: 91925

ASP.NET MVC: Access logs

On an ASP.NET MVC website, what's the best way to implement access logging? I want to answer the following questions:

  1. What are the most popular pages?
  2. Which pages were accessed in the last 24 hours?
  3. etc.

I could log in to the server using Remote Desktop and poke through the IIS logs myself (even using Microsoft Logfile Parser), but I'd like to be able to run reports from the admin pages of my site.

What's the best way to do this? Should I:

  1. Add tracing to all of my controller methods?
  2. Add an IHttpFilter (or whatever) and have that do the logging?
  3. Configure IIS (IIS7 on Windows 2008) to log to a table in my database, and then define an NHibernate mapping for this table?
  4. Something else?

Upvotes: 4

Views: 2323

Answers (4)

Andrei Rînea
Andrei Rînea

Reputation: 20800

I counter logging strictly server-side. You need some client-side code to execute to count cache reloads and such. That's why all modern web analytics (such as Google Analytics and more) have a client-side piece of... code too.

Output cache can also be a pain when doing logging if you don't insert an HttpModule before the Output cache module and so on.

Upvotes: 0

SpoBo
SpoBo

Reputation: 2158

Why not just use [Google Analytics]?(http://www.google.com/analytics/) In my opinion a far simpler way to get these statistics. Plus you'll get a wealth of bonus information. Not to mention you have acces to it anywhere in the world.

Upvotes: 0

Craig Stuntz
Craig Stuntz

Reputation: 126587

Sebastian's answer is certainly not bad (up-voted), however, it is re-implementing functionality already available in IIS. IIS's logging will probably work better than something homegrown, too. (For example, it will log stuff which doesn't pass through the MVC stack.) For that reason, I would favor using something along the lines of your option 3.

Upvotes: 0

Related Questions