Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Not all Audited entities are audited #7491


User avatar
0
p.j.keukens created

Hi,

I have a problem with auditing. I have several classes that have auditing enabled but only some of them are actually audited.

All my entityclasses have FullAuditedEntity and the classes have the Audited attribute.

Also when I go to the change logs there are only 5 object types and not all entities that have the audited attribute are showing up.

Am I missing something?


12 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi @p.j.keukens by change log do you mean entity history?

  • User Avatar
    0
    p.j.keukens created

    yes I mean Entity History

  • User Avatar
    0
    p.j.keukens created

    Some of these objects are generated inside a hangfire job, might that be the problem?

  • User Avatar
    0
    ryancyq created
    Support Team

    AuditedEntities are not tracked in Entitt History by default.

    You will need to add the entity types in TrackedTypes.

    See https://docs.aspnetzero.com/documents/aspnet-core-angular/latest/Features-Angular-Entity-History

  • User Avatar
    0
    p.j.keukens created

    I've added the entity types to the TrackedTypes, most of them are oké now.

    Still some entities that are created inside a hangifre job don't get an entity change log. When I change the entity in the application it get's logged but not when it's created inside a hangfire job.

    Iside the job I do:

    using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
    {
        InsuranceInvoice.Invoice invoice = new InsuranceInvoice.Invoice { amount = 1000 };
        .....
        ....
        await _InsuranceInvoiceRepository.InsertAsync(invoice);
    
        await uow.CompleteAsync();
        }
    
  • User Avatar
    0
    p.j.keukens created

    Might this be happening because the entity historie is dependant on the iABPSession as stated here (from boilerplate documentation). Because in the scheduled hangfire job there is no session user etc.

    The Entity History tracking system uses IAbpSession to get the current UserId and TenantId.

    Is it possible to make it work in the hangfire jobs? What are the exact dependencies in the entity history to the abpsession?

  • User Avatar
    0
    musa.demir created

    Entity History Helper check if enabled, like seen below.

            private bool IsEntityHistoryEnabled
            {
                get
                {
                    if (!_configuration.IsEnabled)
                    {
                        return false;
                    }
    
    
                    if (!_configuration.IsEnabledForAnonymousUsers && (AbpSession?.UserId == null))
                    {
                        return false;
                    }
    
    
                    return true;
                }
            }
    

    If you want your backgroundjob to track entityhistory you can enable IsEnabledForAnonymousUsers.

    IocManager.Resolve<IEntityHistoryConfiguration>().IsEnabledForAnonymousUsers = true;
    
  • User Avatar
    0
    p.j.keukens created

    Do I have to enable it in my job because my core module already does:

    Configuration.Auditing.IsEnabledForAnonymousUsers = true;
    

    So should I call the line below inside the background job?

    IocManager.Resolve<IEntityHistoryConfiguration>().IsEnabledForAnonymousUsers = true;
    
  • User Avatar
    0
    musa.demir created

    You should do

        Configuration.EntityHistory.IsEnabledForAnonymousUsers = true;
    

    in your module.

  • User Avatar
    0
    p.j.keukens created

    Oké they are in the database now, they are not yet on schowing up on the entity histroy screen but I can probably solve that one. Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @p.j.keukens

    Have you solved this problem ?

  • User Avatar
    0
    p.j.keukens created

    yes thank you.