简体   繁体   English

c#-保留Windows窗体应用程序事件日志的最佳方法是什么?

[英]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.

相关问题 什么是在C#中实现链式事件的最佳方式 - what's the best way to implement chained events in C# 在C#Windows窗体应用程序中存储/读取多个用户设置的最佳方法是什么? - What is the best way to store/read multiple user settings in a C# Windows Form Application? 在C#中创建具有多个屏幕的Windows Mobile应用程序的最佳方法是什么? - What's the best way to create a Windows Mobile application with multiple screens in C# 在C#中设计全屏应用程序的最佳方法是什么? - What's the best way to design a full screen application in C#? 在全局事件中使用c#处理事件的开始和结束时间的最佳方法是什么 - What's the best way of handling begin and end times for an event in c# where the events are global Windows注销后如何继续运行C#应用程序 - how to keep running C# application after windows log off 在C#中处理跨线程事件的最佳方法是什么 - What is the best way to handle cross-thread events in C# 在容器 class 内处理 C# 事件的最佳方法是什么? - What is the best way to handle C# events inside a container class? 在MySQL中使用C#Windows窗体,什么是清除用户数据的最佳方法。 - Using a C# windows form with MySQL, what is the best way to sanitise the user data. C#UI多个KeyDown事件?? Windows窗体应用程序 - C# UI multiple KeyDown Events ?? windows form application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM