Base solution for your next web application
Open Closed

AuditLog - PerTenant #4297


User avatar
0
pankajmathur created

Hi,

I would like to disable the audit log for an individual tenant through a setting. When I say disable audit log, I essentially means neither it should write in Logs.txt file nor it should write in ABPAuditLogs table. Is this available out of the box? If yes, how to configure? If No, can you please recommend how can we achieve this?

Regards, Mahendra


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    For audit logs, you can create a custom implementation of IAuditingStore like this:

    public class MyAuditingStore: IAuditingStore, AuditingStore{
    ....
    }
    

    Then, override it's SaveAsync method, check current TenantId from session and save according to it's value. You also need to repalce IAuditingStore in the PreInitialize of your web module like this:

    Configuration.<IAuditingStore, MyAuditingStore>(DependencyLifeStyle.Transient);
    

    For log4net, ABP & AspNet Zero does not provide any way, you can check it on the web how to override Log4Net's behaviour.

  • User Avatar
    0
    pankajmathur created

    Hi ismcagdas,

    thanks for your reply.

    I don't want to loose whatever is getting logged by ABP or Module Zero. All I need the flexibility to log only for certain tenants and not for all tenants. I suspect, if I walk the path that you mentioned, then in that case I may loose all the default logging that ABP or Module Zero is doing. Correct me If my suspicion is wrong.

    Regards, Mahendra

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @pankajmathur,

    You will not loose other logs for audit logs. Your code will be something like this.

    if(LogIgnoredTenantIds.Contains(AbpSession.TenantId)){
        return;
    }
    
    SaveAsync();
    

    According to this code, you will just ignore audit logs for specific tenants.

  • User Avatar
    0
    pankajmathur created

    Hi,

    " You also need to repalce IAuditingStore in the PreInitialize of your web module like this: Configuration.<IAuditingStore, MyAuditingStore>(DependencyLifeStyle.Transient); "

    I am using .Net Core MVC with JQuery version of ABP. In my PreInitialize method of WebMvcModule I don't see the line that you mentioned above to replace. Please advise where to register my class.

    I have created the following class in Application project. Here is the code.

    namespace CitiXsys.iVend365.Auditing { public class CustomAuditing: AuditingStore { public CustomAuditing(IRepository<AuditLog, long> auditLogRepository):base(auditLogRepository) {

        }
        public override Task SaveAsync(AuditInfo auditInfo)
        {
    
            //Check the Tenant here and if logging is not required return from here else call the SaveAsync method of base.
    
            return base.SaveAsync(auditInfo);
        }
    }
    

    }

    Regards, Mahendra

  • User Avatar
    0
    pankajmathur created

    Hi ismcagdas,

    I have successfully implemented the tenant wise logging by walking your recommendation. Thanks for your support..

    Regards, Mahendra