Reputation: 65523
When using Audit.Net in WebApi a scope is created on every controller action event and when we add custom fields they appear at root level in the json. But when we create audit scope manually and if you add any custom fields to audit scope then they are nested under 'customfields' tag. Not sure why this behaviour is different for both the scope type creation.
See the example below:
This is generated by auditscope created when an action on controller is called:
AuditInfo is added through auditScope.SetCustomField("AuditInfo",auditInfo);
{
"EventType": "TestEvent",
"Environment": {
"DomainName": "IIS APPPOOL",
},
"Action": {
"ActionParameters": {
}
},
"RequestBody": {
"Type": "application/json",
"Length": 3191
},
"Headers": {
},
"ResponseHeaders": {
}
},
"AuditInfo": {
"UserIdentifier": "",
"ClaimType": "iss",
"AuditType": 0
},
"id": "",
"_ts": 1627916814
}
Below json is produced when I created AuditScope manually using AuditScope.CreateAsync
method:
"EventType": "TestEvent",
"CustomFields": {
"AuditInfo": {
"UserIdentifier": "",
"ClaimType": "",
"AuditType": 0
}
}
if you observe, AuditInfo is placed under 'CustomFields' tag. Can anyone explain me why it is placing under 'CustomFields' when audit scope is created manually?
Upvotes: 1
Views: 708
Reputation: 13114
This was fixed on the latest Audit.NET.AzureCosmos
version.
Issue: https://github.com/thepirat000/Audit.NET/issues/434
The problem was because the Audit.NET.AzureCosmos
library previoulsy used Microsoft.Azure.DocumentDB.Core
which was coupled to Newtonsoft.Json
, but Audit.NET
targeting .NET 5.0 uses System.Text.Json
, so the JsonExtensionData
and other attributes required on the AuditEvent
were not taken into account.
Now when targeting .NET Standard 2.0 or .NET 5.0, the new client library Microsoft.Azure.Cosmos
is used, and a custom serializer is set so the serializarion is handled by the default serialization mechanism from Audit.Core.Configuration.JsonAdapter
Upvotes: 1