Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laget-se/laget.auditing
A simple framework to audit entities in .NET and .NET Core...
https://github.com/laget-se/laget.auditing
auditing nuget
Last synced: about 1 month ago
JSON representation
A simple framework to audit entities in .NET and .NET Core...
- Host: GitHub
- URL: https://github.com/laget-se/laget.auditing
- Owner: laget-se
- License: apache-2.0
- Created: 2021-06-03T10:14:11.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-06T20:41:45.000Z (2 months ago)
- Last Synced: 2024-11-06T21:36:04.207Z (2 months ago)
- Topics: auditing, nuget
- Language: C#
- Homepage:
- Size: 220 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# laget.Auditing
A simple framework to audit entities in .NET and .NET Core...![Nuget](https://img.shields.io/nuget/v/laget.Auditing)
![Nuget](https://img.shields.io/nuget/dt/laget.Auditing)## Usage
### By
```c#
public class By
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("ip")]
public string Ip { get; set; }
[JsonProperty("referenceId")]
public string ReferenceId { get; set; }
[JsonProperty("superadmin")]
public bool Superadmin { get; set; } = false;
}
```### Auditor
#### Events (built-in)
| | | | | | |
| :- | :- | :- | :- | :- | :- |
| Activated | Added | Archived | Archived | Associated | Attached |
| Cleaned | Cloned | Connected | Created | Deactivated | Deleted |
| Descheduled | Detached | Disassociated |Disconnected | Enqueued | Failed |
| Followed | Information | Inserted | Migrated | Published | Purged |
| Removed | Reported | Restored | Scheduled | Sent | Succeded |
| Unfollowed | Unpublished | Updated |#### .With(Expression> expression, object value)
| Property | Type | Default | Description |
| :-------- | :--------- | :--------------- | :------------ |
| ClubId | int | 0 | Should be set if the event was triggered from the context of a club |
| SiteId | int | 0 | Should be set if the event was triggered from the context of a site |
| System | string | Calling assembly | Indicates what system the event was triggered from, is |
| Reference | object | null | Indicates what object the event refers to, e.g. if you add an attribute for a user the attribute object should be set as the reference |
| By | By (class) | null | Indicates what user, if any, triggered the event |#### Examples
```c#
public class AccountService
{
private readonly IAuditor _auditor;
private readonly IAccountRepository _repository;public AccountService(IAccountRepository repository)
{
_auditor = new Auditor("ServiceBusConnectionString");
_repository = repository;
}public Create(Account account, By by)
{
account = _repository.Create(account, By by);var message = new Created(nameof(Account), account)
.With(x => x.By, by);_auditor.Send(message);
}public Update(Account account, By by)
{
_repository.Update(account);var message = new Updated((nameof(Account), account)
.With(x => x.By, by);_auditor.Send(message);
}public Delete(Account account, By by)
{
_repository.Delete(account);var message = new Deleted((nameof(Account), account)
.With(x => x.By, by);_auditor.Send(message);
}public Remove(Account account, Site site, By by)
{
_repository.Delete(account);var message = new Remove((nameof(Account), account)
.With(x => x.By, by)
.With(x => x.Reference, site);_auditor.Send(message);
}
}
``````c#
public class AccountService
{
private readonly IAuditor _auditor;
private readonly IAccountRepository _repository;public AccountService(IAccountRepository repository)
{
_auditor = new Auditor("ServiceBusConnectionString");
_repository = repository;
}public Create(Account account, By by)
{
var account = new
{
id = 123,
name = "Jane Doe"
};
var site = new
{
id = 123,
name = "FC GonAce"
};var message = new Created("Account", account)
.With(x => x.By, by)
.With(x => x.Reference, site);await _auditor.Send(message);
}
}
```