Reputation: 1364
I notice the AuditScope
got .Event
properties which contains the value the event logs. So it can convert to json by using this command
var Scope = AuditScope.Create("Account:Suspend", () => user);
//Change value properties on user object
//Save into database
//Retrieve eventlog from audit
var EventInJson = Scope.Event.ToJson();
So I decide to not use CustomDataProvider, so I configure Audit.Net like this
Audit.Core.Configuration.Setup();
But the New Object
was missing inside the Target Object
. Sample result
{
"EventType": "Account:Suspend",
"Environment": {
"UserName": "test",
"MachineName": "test",
"DomainName": "test",
"CallingMethodName": "Account.API.Controllers.AccountController+<UpdateSuspend>d__35.MoveNext()",
"AssemblyName": "Account.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"Culture": "en-MY"
},
"Target": {
"Type": "ApplicationUser",
"Old": {
"CountryId": 1,
"IsDeleted": false,
"IsSuspend": true,
"RiskLevelId": 0,
"CreationDate": "2018-10-05T04:51:32.485",
"LastLoginDate": "2018-10-05T04:51:32.486",
"Id": 23,
"UserName": "user",
"NormalizedUserName": "test",
"Email": "[email protected]",
"NormalizedEmail": "[email protected]",
"EmailConfirmed": false,
"SecurityStamp": "Test",
"ConcurrencyStamp": "test",
"PhoneNumberConfirmed": false,
"TwoFactorEnabled": false,
"LockoutEnd": "2018-12-18T04:15:56.2490628+00:00",
"LockoutEnabled": false,
"AccessFailedCount": 0
}
},
"StartDate": "2019-01-08T09:35:34.8363926Z",
"Duration": 0
}
Is possible to use without data provider?
Upvotes: 2
Views: 412
Reputation: 13114
The New
value is missing because it's updated when the scope is Saved, depending on the creation policy it could be when the scope is disposed, or when you explicitly call the Save
method on the AuditScope
. So after you modify the target object and before you get the auditevent, you have to dispose the scope or call its Save
method.
Also note that calling like this Audit.Core.Configuration.Setup();
is not enough to have a NULL data provider, that code will just let the default which is the FileDataProvider
. In order to specify a NULL data provider you can do Audit.Core.Configuration.Setup().UseNullProvider();
Upvotes: 1