Using Json.NET library suggestion
See original GitHub issueFirst of all, thank you for the fantastic library! I have a suggestion for the creation of Bson Document in the following events in Audit.Net MongoDB provider:
- InsertEvent
- ReplaceEvent
- Serialize<T>
We are working on a WebApi Core 2.0 project with MSSQL database and we use MongoDB to save our application logs.
The point is that for saving complex entities with navigation properties we face the following error while saving the records to MongoDB: BsonSerializationException: Maximum serialization depth exceeded (does the object being serialized have a circular reference?) This happened because the ToBsonDocument() method can’t Ignore Reference Loopings and always return an exception.
We had a quick fix for this issue as followed.
Changing this part in InsertEvent/ReplaceEnevt:
var doc = auditEvent.ToBsonDocument();
to this:
var doc = BsonDocument.Parse(JsonConvert.SerializeObject(auditEvent, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
and also this part in Serialize<T>:
return value.ToBsonDocument(typeof(object));
to this:
return BsonDocument.Parse(JsonConvert.SerializeObject(value, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
OR
You may add a setting to the UseMongoDB configuration so that Ignoring Reference Looping can be enabled or disabled.
Any suggestion or additional configuration would be appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
This is included from version 9.0.0.
Feel free to re-open the issue is you’re still having problems.
That would be great!