由于一个系统的需要,需要在日志中加入自定义的信息,并且需要根据需要过滤显示其中的部分操作记录入修改,删除等,其他的不显示,具体的实现方法如下:
一、需要继承 AuditDataItemPersistent,具体代码如下:
public MyAuditDataItemPersistent(DevExpress.Xpo.Session session) : base(session) { } [XafDisplayName("修改标题")] public string PropertyCaption { get { if (AuditedObject != null) { try { var caption = CaptionHelper.GetMemberCaption(AuditedObject.Target.GetType(), PropertyName); return caption; } catch { } } return string.Empty; } } }
二、在WinApplication.cs中设置Audit的存储对象为MyAuditDataItemPersistent
三、
[XafDisplayName("修改日志")] IList<MyAuditDataItemPersistent>Xt_Order_Review_Detail_Audit { get; } [DomainLogic(typeof(Xt_Order_Review_Detail_Dc))] public class ContactLogic { private static XPCollection<MyAuditDataItemPersistent> _changeHistory; public static IList<MyAuditDataItemPersistent> Get_Xt_Order_Review_Detail_Audit(Xt_Order_Review_Detail_Dc obj, IObjectSpace os) { var source = AuditedObjectWeakReference.GetAuditTrail(((XPObjectSpace)os).Session, obj); if (source != null) { try { _changeHistory = new XPCollection<MyAuditDataItemPersistent>(((XPObjectSpace)os).Session, source); _changeHistory.Filter = CriteriaOperator.Parse("OperationType='ObjectChanged'"); } catch { } } return _changeHistory; //return (MyAuditDataItemPersistent)DevExpress.Persistent.BaseImpl.AuditedObjectWeakReference.GetAuditTrail(((XPObjectSpace)os).Session, obj); }