Base solution for your next web application
Open Closed

Audit Logging - Only Exceptions #3472


User avatar
0
pumbinha created

Hi all,

because a lot of traces are being recorded in the audit log I was wondering if it was possible to set some kind of level to save only the traces that generate an exception.

If this is not possible "out of the box", is it possible to extend the audit-log framework to achieve this?

Thank you in advance.


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

    Hi,

    It is not possible out of box but you can override SaveAsync method of this class <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero.Common/Auditing/AuditingStore.cs">https://github.com/aspnetboilerplate/mo ... ngStore.cs</a> and don't save audit log if auditInfo.Exception is null.

    Thanks.

  • User Avatar
    0
    pumbinha created

    <cite>pumbinha: </cite> Hi all,

    because a lot of traces are being recorded in the audit log I was wondering if it was possible to set some kind of level to save only the traces that generate an exception.

    If this is not possible "out of the box", is it possible to extend the audit-log framework to achieve this?

    Thank you in advance.

    This means, that I can use my own AuditingStoreProvider or should I create a new class that inherits from AuditingStore and there I write my own business logic?

    I can't find any place in code where the AuditingStoreProvider is set.

  • User Avatar
    0
    pumbinha created

    Well, I finally found a solution, I leave it here just in case it's useful for someone:

    I've created my own AuditingStore class:

    public class AuditingStoreExtended : AuditingStore
        {
            public AuditingStoreExtended(IRepository<AuditLog, long> auditLogRepository) : base(auditLogRepository)
            {
            }
    
            public override Task SaveAsync(AuditInfo auditInfo)
            {
                Task result = Task.FromResult(new AuditLog()); ;
    
                if (auditInfo.Exception != null)
                {
                    result = base.SaveAsync(auditInfo);
                }
    
                return result;
            }        
        }
    

    After this I injected this new class in XXXCoreModule.cs:

    IocManager.Register<IAuditingStore, AuditingStoreExtended>();
    

    And now it works perfectly :)

    Is this what you meant?

    Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @pumbinha,

    Yes, that's it :). I forgot to share dependency injection registration part, sorry.