Multiple logs within same api #600
Replies: 2 comments 3 replies
-
Please share the code where you're trying to do multiple logs. Note that each AuditScope instance is related to only one audit event. |
Beta Was this translation helpful? Give feedback.
-
An AuditScope instance is for a single AuditEvent, so you cannot use the same scope to store different audit events. However, you could have a custom list field on your API audit event and store your multiple table events in the same AuditEvent like this. private void AddLogs(AuditLogsInput input)
{
var scope = this.GetCurrentAuditScope();
if (!scope.Event.CustomFields.ContainsKey("InputEvents"))
{
scope.Event.CustomFields["InputEvents"] = new List<AuditLogsInput>();
}
// Include the table event input in the audit event custom list field
((List<AuditLogsInput>)scope.Event.CustomFields["InputEvents"]).Add(input);
} So you'll end up having events like this: {
"Action": {
"TraceId": "40000086-0003-ff00-b63f-84710c7967bb",
"ControllerName": "Values",
"ActionName": "Get",
...
},
"EventType": "MVC",
"Environment": {
...
},
"InputEvents": [
{
"comment": "test1",
"source_table_id_uuid": "table1",
"module_table_link_id": 1,
"ip_address": "1.2.3.4",
"browser_name": "test1"
},
{
"comment": "test2",
"source_table_id_uuid": "table2",
"module_table_link_id": 2,
"ip_address": "4.3.2.1",
"browser_name": "test2"
}
]
} Another possibility is to create a new audit scope for each of your table events and correlate the table events with the API events with some correlation value, for example: private void AddLogs(AuditLogsInput input)
{
var scope = this.GetCurrentAuditScope();
var apiAction = scope.Event.GetWebApiAuditAction();
// Create and save the table event right away
AuditScope.Log("TableEvent", new
{
TraceId = apiAction.TraceId,
InputEvent = input
});
} |
Beta Was this translation helpful? Give feedback.
-
Hi @thepirat000
while using audit web api, need to add multiple logs in same api method,
var auditScope = this.GetCurrentAuditScope();_
creating above scope and adding a comment in that api,
so similarly need to add two different logs
tried to add multiple logs but its like one instance is only added in the logs the last one in the flow and the previous one are ignored
regards.
Beta Was this translation helpful? Give feedback.
All reactions