Coder Social home page Coder Social logo

Comments (2)

thepirat000 avatar thepirat000 commented on June 20, 2024

You can accomplish what you want by setting up a custom action that discards the audit scope, so the audit event won't be saved:

Audit.Core.Configuration.AddCustomAction(ActionType.OnEventSaving, scope =>
{
    if (scope.GetWebApiAuditAction().ResponseStatusCode == 404)
    {
        scope.Discard();
    }
});

Anyway, you can work on a PR if you want, very welcome!

Take into account that:

  • There is no IncludeResponseBodyIf. Not sure if you are referring to the middleware's IncludeResponseBody(Func<HttpContext, bool> includePredicate) but that cannot filter on the response, since the predicate is executed before the action method is called.
  • The AuditScope/AuditEvent is created before the server processes the request, so if we provide a method to filter audits depending on the response, we should maybe call it DiscardIf, or something like that.

from audit.net.

esbenbach avatar esbenbach commented on June 20, 2024

Ahh thanks for the explanation

I was mixing up IncludeResponseBodyFor and LogActionIf.

Since I messed up that I ust want to be clear:
I am talking about adding another Property to the AuditApiAttribute if possible.
Presuambly it should be DiscardIfNot or ExcudeAuditIfNot (the negation in the naming here would be because I think the most common need is to only audit on success, and listing ALL the status codes you want to discard seems tedious).

I will give it a spin and see what comes out of it, feel free to reject the idea before it gets anywhere :D

from audit.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.