Base solution for your next web application
Open Closed

5.4.0 Entity history #5092


User avatar
0
BobIngham created

.Net core, angular, 5.4.0 I download the new version and set up as per instructions. I login as the default tenant and add a new Organization Unit. I go to Audit Logs and can see the Operation for CreateOrganizationUnit in the Operation log tab. I switch tabs to Change logs and can not see the creation, I select the admin user and the OrganizationUnit entity and can still not see any changes. I update the Organization Unit and return to the Audit Log -> Change log tab and can still not see any changes.

Am I missing something?


6 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Uncomment this line in *EntityFrameworkCoreModule:

    //Uncomment below line to write change logs for the entities below:
    //Configuration.EntityHistory.Selectors.Add("AbpZeroTemplateEntities", typeof(OrganizationUnit), typeof(Role), typeof(Tenant));
    
  • User Avatar
    0
    BobIngham created

    Doh! Thanks, Aaron. But I'm sure i saw a post whereby auditability had been switched on by default.

  • User Avatar
    0
    aaron created
    Support Team

    Yes. From the documentation on Entity History:

    Entity History is enabled by default. You can disable it as shown below:

    public class MyModule : AbpModule
    {
       public override void PreInitialize()
       {
           Configuration.EntityHistory.IsEnabled = false;
       }
    
       //...
    }
    

    But:

    No entities are automatically tracked by default. You should configure entities either by using the startup configuration or via attributes.

  • User Avatar
    0
    BobIngham created

    Hi Aaron,

    Just to be clear, I add the following lines to ProjectnameEntityFrameworkCoreModule (I am tracking history for all fully audited entities):

    Configuration.EntityHistory.IsEnabled = true; //Enable this to write change logs for the entities below:
    Configuration.EntityHistory.Selectors.Add("NuagecareEntities", typeof(OrganizationUnit), typeof(Role), typeof(User), typeof(Tenant));
    Configuration.EntityHistory.Selectors.Add(
        new NamedTypeSelector(
            "Abp.FullAuditedEntities",
            type => typeof(IFullAudited).IsAssignableFrom(type)
         ));
    

    Can you tell what the following lines are for in AuditLogAppService and do I need to change anything?

    public List<NameValueDto> GetEntityHistoryObjectTypes()
    {
        var entityHistoryObjectTypes = new List<NameValueDto>();
    
        if (AbpSession.TenantId == null)
        {
            entityHistoryObjectTypes.Add(new NameValueDto(L("Nuagecare.MultiTenancy.Tenant"), "Nuagecare.MultiTenancy.Tenant"));
        }
        entityHistoryObjectTypes.Add(new NameValueDto(L("Nuagecare.MultiTenancy.Role"), "Nuagecare.MultiTenancy.Role"));
        entityHistoryObjectTypes.Add(new NameValueDto(L("Abp.Organizations.OrganizationUnit"), "Abp.Organizations.OrganizationUnit"));
    
        return entityHistoryObjectTypes;
    }
    

    Thanking you in advance....

  • User Avatar
    0
    aaron created
    Support Team

    It's used in Audit Log pages: https://github.com/aspnetzero/aspnet-zero-core/search?q=GetEntityHistoryObjectTypes

    You can add your entities if you want to view them.

  • User Avatar
    0
    BobIngham created

    Makes perfect sense, thanks.