Everytime users did something like add, delete or edit data.
I want to keep the record of it. So system admin can see who did what later.
For example
private AddUser(User id)
{
if(id != null)
{
MessageBox.Show("Item Updated");
string sqlAddUser = "INSERT INTO 'DATABASE.USER' VALUES (Item.ID, Item.Name, Item.Address)";
if(db.SqlNonQuery(sqlAddUser) //If successful
{
///To DO : Add system log into database
///Ex. string sqlLog = DateTime.Now + User.ID + " added Item ID " + item.ID;
}
else
{
MessageBox.Show("Error");
}
}
}
Is there any better way or common practice to do it? Thank you.
In general for logging, I recommend Log4Net; it’s highly configurable and works great.
However, if you don’t want to invest the time in implementing a third-party component and wanted to log to the database, you could do your data access via stored procedure, and have an
INSERTinto a logging table as part of the SP.