C# 如何使用Asp.net和SQL Server审核登录应用程序?

C# 如何使用Asp.net和SQL Server审核登录应用程序?,c#,.net,sql-server,audit-logging,C#,.net,Sql Server,Audit Logging,我在SQL Server表中创建了以下列: Log_id Old_value New_value Module [The module for the transaction] Reference_id [unique id of the record from respective tbl to associate with transaction history] Transaction [The type of transaction. Can include, INSERT, UPDAT

我在SQL Server表中创建了以下列:

Log_id
Old_value
New_value
Module [The module for the transaction]
Reference_id [unique id of the record from respective tbl to associate with transaction history]
Transaction [The type of transaction. Can include, INSERT, UPDATE or DELETE]
Transaction_status [Indicates SUCCESS or FAILURE]
Stack_trace [The detailed stack trace of the error]
Modified_on
Modified_by
在插入、更新或删除时,将相关数据插入上述审计表的最佳方式是什么


请给我一些建议。谢谢

最好的效率取决于很多事情:加载数据库(有多少更新,有多大),您将如何处理数据,等等

但一种方法是使用触发器: 和

触发器可能在修改时出现问题。这是ASP.NET,所以很有可能是一个到SQL的单一连接,只有ASP知道修改的方法

如果日志的所有信息都已在SQL中,则触发

如果日志需要SQL中尚未包含的信息,那么最佳和高效就不一样了

通过存储过程的两个独立语句将是最有效的

但是为了数据完整性,将这两条语句包装在一个事务中,以便它们作为一个单元成功或失败。很少的开销。同样在存储过程中。或者,在代码背后,您可以使用TSQL和事务,但存储过程将更快、更安全


还要查看日志上的索引。索引越少,插入速度越快。在日志中,您可能希望优化插入速度而不是选择速度

执行insert语句,将asp.net代码中的记录插入到需要记录的位置。