I have a web app that contains an activity log for actions the users take. There are multiple types of activities that can be logged.
Here's an example:
public static class NewAccountActivity() {
public static Write(string username) {
//... do stuff to enter a new account activity into the database ...
}
}
public static class NewPostActivity() {
public static Write(string username, long postId, string postTitle) {
//... do stuff to enter a new post activity entry into the database ...
}
}
And then go on to create a new class for every single type of activity to log. Each activity has a .Write() method, with a unique signature for each one (as shown in the code example above)
And then in my web app (asp.net mvc based) I use them like this:
public ActionResult NewAccount(Account account) {
if (Model.IsValid(account)) {
//... do new account stuff ...
NewAccountActivity.Write(account.UserName);
//... redirect to action, or show view ...
}
}
public ActionResult NewPost(Post post) {
if (Model.IsValid(post)) {
//... do new post stuff ...
NewPostActivity.Write(post.UserName, post.postId, post.Title);
//... redirect to action, or show view ...
}
}
Is this a bad idea? Is there a better way? Should these be a bunch of methods jammed into one class?
I started doing this because of an answer to a different question I had on SO.