Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collecting Stats on an asp.net mvc site?

Hi I need some advice.

I need a way to keep track of user activity on my site, without third party tools (such as google anayltics).

So basically any request that comes to my site I need to fire of an a async task that would collect info on the user and write to DB. What's the best way to do this?

I have tried to write an async httphandler but I couldn't get to work. It's hit multiple times for each request (for all the resourse files like css jpg ...).

like image 356
usermon Avatar asked Nov 05 '22 09:11

usermon


1 Answers

I'm currently using log4net to do something similar.

I setup my log4net very similar to what this article did. After that you can create a logger Attribute that inherits the ActionFilterAttribute that you can attach to your controllers, I personally have a base controller that I applied my logger attribute to.

In your attribute you'll override OnActionExecuting and log all the information about the currently executing action in your log4net logger that you want. Just make sure you include base.OnActionExecuting(filtercontext) you don't want to screw up any of the mvc plumbing, you are just hooking into it at a point to do some logging.

like image 131
ajrawson Avatar answered Nov 13 '22 05:11

ajrawson