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)
-
0
Hi @p.j.keukens by
change logdo you mean entity history?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
yes I mean Entity History
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Some of these objects are generated inside a hangfire job, might that be the problem?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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(); }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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;Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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;Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
You should do
Configuration.EntityHistory.IsEnabledForAnonymousUsers = true;in your module.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @p.j.keukens
Have you solved this problem ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
yes thank you.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)