This is a small auditing package
The need for auditing already exists in projects,
the requirement to log information to prove something happened,
but also to capture who
, what
and when
a business action happened.
AuditBot
helps in generating tracking information about operations being executed.
It gathers environmental information such as the caller
user id
, machine name
, method name
, exceptions
,
including execution time
.
This library is implemented as a Middleware class that can be configured to log requests that does not reach the action filter (i.e. unsolved routes, parsing errors, etc).
- capture who with the
IPrincipal
orIClaimsPrincipal
- Audit log channel
- Install-Package AuditBot
- Once you have configured the
AddAuditBot()
service in the Startup.cs file,- Once you have configured the
UseAuditBot()
configure in the Startup.cs file, you're ready to define theAuditBotOptions
in theapp.settings.json
.
The audit can only be enabled as Action Filter
:
Decorating the controllers/actions to be audited with
following action filter attribute.
- [Auditor()]
- EventType :
Specify the type of event you want to audit
- IncludeResponseBody :
Enable response body to be audited
- IncludeRequestBody :
Enable request body to be audited
- IncludeModelState :
Enable state of the request body to be audited
- MailIfError :
Enable send email when something happends
- EventType :
- [IgnoreAuditor]
Copy the below code to your project appsettings.
"AuditBotOption": {
"ApplicationName": "auditbot-demo-api",
"Source": "AuditBot.Demo.Api",
"SubjectId": "sub",
"SubjectClaim": "name",
"IncludeFormVariables": false,
"ClientIdClaim": "client_id",
"Mail": {
"Driver": "SMTP",
"Host": "smtp.gmail.com",
"Port": 587,
"Username": "[email protected]",
"Password": "PersolAudit@2021!",
"From": {
"Address": "[email protected]",
"Name": "no-reply"
}
},
"DataSource": {
"Enabled": true,
"SqlServer": {
"ConnectionId" : ""
}
}
}