[英]c# - What's the best way to keep log for events of windows form application?
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 ; 通常,对于日志记录,我建议使用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 INSERT
into a logging table as part of the SP. 但是,如果您不想花费时间来实现第三方组件并希望登录到数据库,则可以通过存储过程进行数据访问,并且可以将INSERT
到日志表中作为SP的一部分。 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.