您如何为您的对象实施审计跟踪(编程)? [英] How do you implement audit trail for your objects (Programming)?

查看:32
本文介绍了您如何为您的对象实施审计跟踪(编程)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的对象上实现添加/编辑/删除的审计跟踪,我使用 ORM (XPO) 来定义我的对象等.我实现了一个在

I need to implement an audit trail for Add/Edit/Delete on my objects,I'm using an ORM (XPO) for defining my objects etc. I implemented an audit trail object that is triggered on

  1. OnSaving
  2. OnDeleting

对于基础对象,我将更改存储在 Audit-AuditTrail (Mast-Det) 表中,用于字段更改.等使用一些方法服务调用.

Of the base object, and I store the changes in Audit-AuditTrail (Mast-Det) table, for field changes. etc. using some method services called.

您如何在 OOP 代码中实施审计跟踪?请分享您的见解?有什么图案之类的吗?最佳实践等?另一件事是如何在运行单元测试时禁用审计,因为我不需要审计它们但是因为基础对象有代码.

How do you implement audit trail in you OOP code? Please share your insights? Any patterns etc? Best practices etc? Another thing is that how to disable audit when running unit test,since I don't need to audit them but since base object has the code.

对对象的更改(编辑/添加/删除)以及需要审核哪些字段更改

Changes to object (edit/add/del) and what field changes need to be audited

推荐答案

如果可以,数据库触发器是首选方式.

Database triggers are the preferred way to go here, if you can.

但是,最近我不得不在客户端代码中执行此操作,并且我最终编写了一个类,该类在打开对象进行编辑时创建了对象的深度(值)副本,并在保存时比较了两个对象(使用ToString() only) 并将任何更改写入审计表.

However, recently I had to do this in client-side code and I ended up writing a class that created a deep (value) copy of the object when it was opened for editing, compared the two objects at save time (using ToString() only) and wrote any changes to an audit table.

我在每个我想要考虑可审计的属性上都有一个 [Audit] 属性,并使用反射来查找它们,使该方法不特定于被审计的对象.

I had an [Audit] attribute on each property I wanted to consider auditable and used reflection to find them, making the method non-specific to the objects being audited.

这篇关于您如何为您的对象实施审计跟踪(编程)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆