Reputation: 63
I am trying to build a log that contains each action been done in my application like adding or removing data and so on . I googled and understood that i must use
System.Security.Principal.WindowsIdentity.currentuser()
this will tell me who is the current user but how can i record the actions done by this particular user ?
Thanks in advance :)
Upvotes: 0
Views: 1350
Reputation: 10287
In order to log applicative actions done by the current user, you need to log them manually using libraries like log4net
or on your own.
In order to make it easier for you and make your code shorter, you should consider design patterns like Interceptor
(sort of Decorator Factory
that can be implemented easily using Castle Winsdor library
or post-sharp
though the later is more unexpected) to decrease the amount of times you need to log manually (by Intercepting the class doing your actions and make it log in every desired method call by Attributing
the logged methods).
Upvotes: 1
Reputation: 293
I've run into this problem as well. I was planning to add a seperate logging method to each custom action. eg: When a user deletes an object, a method activates to save the necessary info.
Though I might be making it more difficult than necessary.
Upvotes: 1
Reputation: 60564
Whenever your system performs some action initiated by the user, write something to a log file (or log table in a database, or whatever storage mechanism you prefer) that contains some information that identifies the user, for example the user name (which you get from System.Windows.Principal.WindowsIdentity.GetCurrent().Name
).
Upvotes: 1
Reputation: 2574
It depends on where you want to record those actions and what the actions are. You can write a SQL query that will save the data in a table, you cn use libraries like log4net. But remember if you want to record action per page/class, this need to be in every class.
Upvotes: 1