Comments (8)
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.
ToJson method?
from audit.net.
JsonSerializer.Serialize(interceptEvent.Result.Value), or whatever
from audit.net.
Hello again,
interceptEvent is getting always null.
from audit.net.
You should share your audit configuration and/or a sample minimal project that reproduces the issue
from audit.net.
you can find a test project below link
https://github.com/accacc/AuditTestApi
from audit.net.
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.
Closing this for inactivity. If you're still having the issue please comment below
from audit.net.
Related Issues (20)
- Support CancellationToken on all async methods HOT 3
- I get a missing method Exception when saving HOT 11
- Response content not capturing correctly when Exception Handlers is used HOT 1
- [AuditApi] - override middleware settings with controller attributes HOT 3
- Error on inserting Audit Data HOT 2
- EF Core value updates not audited HOT 3
- EF Core value updates are not audited HOT 13
- Custom field empty in Entries Array HOT 3
- Bump Microsoft.Bcl.AsyncInterfaces HOT 1
- Limited configuration of MongoDB provider HOT 1
- Related object causes multiple audit entries HOT 3
- Question for WebApi: Audit only on statuscodes HOT 2
- How to use WebApi / Serilog with .Net 4.7.2 HOT 9
- Extra Double Quote in PostgreSqlDataProvider Generated SQL HOT 2
- Sometimes when auditing to CosmosDB a CosmosException occurs HOT 5
- Since the new version of mongo-csharp-driver The Jobject for AuditTarget cannot be serialized/deserialized HOT 2
- AuditCommandInterceptor IncludeReaderResults = true results in "DataReader Open" error HOT 9
- Missing Method Exception: Microsoft.EntityFrameworkCore.Metadata.IEntityType.GetProperties() HOT 3
- Best way to "Include" related entity properties HOT 3
- Audit.EntityFramework.Core add support for EF8 Complex Types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audit.net.