Ends in:
5 DAYS
23 HRS
7 MIN
4 SEC
Ends in:
5 D
23 H
7 M
4 S
Open Closed

Intercept audit log - track entity instance level differences #6853


User avatar
0
DominaTang created

With ABP Framework, when entity data is changed, it is written to AbpEntityChanges and AbpEntityPropertyChanges table.

Is the a way intercept Abp's implementation, so that we can do this: Get Old Entity Instance value, Get new Entity Instance value, this entity change is triggered via which API and by who. Then we sent whole data to an event bus.

Thanks

  • ABP Framework version: v7.2.1 Micro Service *:

3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes, you can create an AuditLogContributor.

    https://docs.abp.io/en/abp/latest/Audit-Logging#audit-log-contributors

    For example:

    public class MyAuditLogContributor : AuditLogContributor
    {
        public override void PostContribute(AuditLogContributionContext context)
        {
            var distributedEventBus = context.ServiceProvider.GetRequiredService<IDistributedEventBus>();
            foreach (var entityChange in context.AuditInfo.EntityChanges)
            {
                foreach (var propertyChange in entityChange.PropertyChanges)
                {
                    var oldValue = propertyChange.OriginalValue;
                    var newValue = propertyChange.NewValue;
                    
                    distributedEventBus.PublishAsync(...)
                }
            }
        }
    }
    
  • User Avatar
    0
    DominaTang created

    Can ABP framework put Snapshot of old entity instance and new instance ExtraProperties in JSON format. Since sometimes, there is such audit requirement. For example, previous form submitter is A, new submitter is still A, this property is not changed. However, for audit perspective, the app needs to show who make such changes or even for property is not changed, the snapshot value should still show on the UI.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can do it yourself.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 26, 2024, 12:49