https://github.com/pandatecham/be-lib-audittrail
https://github.com/pandatecham/be-lib-audittrail
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pandatecham/be-lib-audittrail
- Owner: PandaTechAM
- License: mit
- Created: 2024-04-26T13:15:33.000Z (almost 2 years ago)
- Default Branch: development
- Last Pushed: 2024-11-21T21:09:24.000Z (about 1 year ago)
- Last Synced: 2025-03-18T19:30:33.235Z (10 months ago)
- Language: C#
- Size: 219 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE.txt
- Audit: AuditTrail.sln
Awesome Lists containing this project
README
- [1. Pandatech.AuditTrail](#1-pandatechaudittrail)
- [1.1. Features](#11-features)
- [1.2. Getting Started](#12-getting-started)
- [1.3. Usage](#13-usage)
- [1.3.1. Implement IAuditTrailConsumer Example:](#131-implement-iaudittrailconsumer-example)
- [1.3.2. Add Services Example:](#132-add-services-example)
- [1.3.3. Create Rule Example:](#133-create-rule-example)
- [1.3.4. Create Custom Rule Example:](#134-create-custom-rule-example)
- [1.5. Limitations](#14-limitations)
- [1.5. Contributing](#15-contributing)
- [1.6. License](#16-license)
# 1. Pandatech.AuditTrail
Pandatech.AuditTrail is a tool meticulously crafted to gather vital entity data from the change tracker post DbContext
SaveChanges operation.
## 1.1 Features
Audits necessary entities for logging or preserving modified property data.
Offers a convenient fluent configuration to specify tracked entities with ease.
## 1.2 Getting Started
Install the package via NuGet Package Manager or use the following command:
```bash
Install-Package Pandatech.AuditTrail
```
## 1.3 Usage
- Implement `IAuditTrailConsumer` interface.
- Add AddAuditTrail services by providing `IAuditTrailConsumer` implementation.
- Create a rules derived from `EntityRule`.
### 1.3.1. Implement IAuditTrailConsumer Example:
Implement the `IAuditTrailConsumer` interface.
To be able to retrive modified entities data after save operation.
```csharp
public class AuditTrailConsumer() : IAuditTrailConsumer
{
public async Task ConsumeAsync(IEnumerable> auditData,
DbContextEventData? eventData,
CancellationToken cancellationToken = default)
{
// Handle tracked entites here.
}
}
```
### 1.3.2. Add Services Example:
```csharp
builder.Services.AddAuditTrail>(typeof(Registration).Assembly);
services.AddDbContextPool((sp, options) =>
{
options.UseAuditTrail(sp);
});
```
### 1.3.3 Create rule example:
Create a rule derived from `EntityRule`.
```csharp
public class UserRule : EntityRule
{
public UserRule(ISomeService someService)
{
SetPermission(PermissionType.Users_Read);
RuleFor(s => s.PasswordHash).Ignore();
RuleFor(s => s.Status).ChangeName("UserStatus");
}
}
```
### 1.3.4 Create Custom Rule Example:
You can create your own rules and modify properties as needed.
```csharp
public class ChangeNamePropertyRule : PropertyRule
{
private readonly string _changeName;
public override NameValue ExecuteRule(string name, object value)
{
return new NameValue(_changeName, value);
}
public ChangeNamePropertyRule(string name)
{
_changeName = name;
}
}
public static class RuleExtensions
{
public static IRuleBulder ChangeName(this IRuleBulder ruleBuilder, string name)
where T : class
{
var rule = new ChangeNamePropertyRule(name);
return ruleBuilder.SetRule(rule!)!;
}
}
```
## 1.4 Limitations
- In case of composite keys only first key will be selected as entityId.
## 1.5. Contributing
Contributions are welcome! Please submit a pull request or open an issue to propose changes or report bugs.
## 1.6 License
Pandatech.AuditTrail is licensed under the MIT License.