Coder Social home page Coder Social logo

Comments (8)

thepirat000 avatar thepirat000 commented on June 3, 2024

I think it's the same problem as for #152 (here) and #499. Please take a look.

The problem seems to be Elasticsearch's Dynamic Mapping.

The first time you insert to the index, it will dynamically map the type of the result / arguments depending on its value, but they could hold an object or a concrete value depending on the proxied method that's being audited. I'm assuming you want to store all the methods audited to the elasticsearch index.

So, for example, if the first audited method was void CreateOrder(Order order), then the audit arguments.value will be mapped as an object, but if the second audited method is void GetOrder(int id), then the audit argument.value will be a concrete value and the index insertion will fail.

I think one way to solve it is to force all the "object" values, to be mapped as JSON objects, for example using a Custom Action that will execute before the audit event save operation:

Audit.Core.Configuration.AddOnSavingAction(scope =>
{
    var interceptEvent = scope.GetAuditInterceptEvent();
    foreach (var arg in interceptEvent.Arguments)
    {
        arg.Value = ToJson(arg.Value);
    }

    interceptEvent.Result.Value = ToJson(interceptEvent.Result.Value);
});

from audit.net.

accacc avatar accacc commented on June 3, 2024

ToJson method?

from audit.net.

thepirat000 avatar thepirat000 commented on June 3, 2024

JsonSerializer.Serialize(interceptEvent.Result.Value), or whatever

from audit.net.

accacc avatar accacc commented on June 3, 2024

Hello again,

interceptEvent is getting always null.

from audit.net.

thepirat000 avatar thepirat000 commented on June 3, 2024

You should share your audit configuration and/or a sample minimal project that reproduces the issue

from audit.net.

accacc avatar accacc commented on June 3, 2024

you can find a test project below link

https://github.com/accacc/AuditTestApi

from audit.net.

thepirat000 avatar thepirat000 commented on June 3, 2024

scope.GetAuditInterceptEvent() will return null for any audit event that is not generated by Audit.DynamicProxy, for example the audit events generated by Audit.WebApi extension (for which you could call scope.GetWebApiAuditAction() to get the info).

Also interceptEvent.Arguments will be NULL when the audited method has no parameters, so you should probably add some validations.

Note that any argument passed to (or the result returned from) an audited proxied method should be JSON serializable, since you're indexing the audits to Elasticsearch. But your ProductService methods are returning DbSet which is not serializable.

For this, you have two options:

  • Ignore the audits for the entities that are not serializable
[return: AuditIgnore]  // Ignore the return value in the audits
public IEnumerable<ProductEntity?> GetProducts()
{
    return _dbContext.Products;  // Note this is a DbSet<ProductEntity>
}

or

  • Return serializable entities from your methods
public IEnumerable<ProductEntity?> GetProducts()
{
    return _dbContext.Products.ToList();  // return a list
}

from audit.net.

thepirat000 avatar thepirat000 commented on June 3, 2024

Closing this for inactivity. If you're still having the issue please comment below

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.