I have an MVC2 web application that needs to record the number of unique logins by users. Each time a user logs in, there needs to be a record saved to a database. Just the basics like time, date and the like.
Given that the business requirements are to log only cases in one specific ActionResult (i.e. user logon), should I simply write some custom code to fire a record through to the database?
Alternatively, given the company does have a track record of later on changing their mind (uncommon as that is with clients), might I be better to create something a little more robust and use that?
Finally, what about using Log4Net instead? Given that the initial requirements only focus on one small part of one application, is that overkill even though it might be more extensible later?
Advice and lively debate appreciated.
Since you are using the
SqlMembershipProvider, the simplest thing to do might be to add anupdate triggerto theaspnet_Membershiptable. WhenLastLoginDateis updated, the trigger can populate a separate tracking table. You can do the same if you want to track failed login attempts using theFailedPasswordAttemptCountcolumn.For more detail on how these fields are updated when the user logs in, see the documentation for the SqlMembershipProvider.ValidateUser method:
With respect to logging in general, you may want to use a logging framework regardless, and I would suggest NLog.