BstAutoLog 10.2.0
BstAutoLog
How to use
Program.cs
services.AddAutoLog<ApplicationDbContext>();
Model.cs: use either interface, or both.
| Interface | What it does |
|---|---|
ILogChanges |
An AutoLogs row when the model is created, updated or deleted. Adds no columns to the model's table. |
IHasAutoLogInfo |
CreateInfo and UpdateInfo columns (time, user, IP) on the model's table. Writes no AutoLogs rows. |
public class Product : ILogChanges, IHasAutoLogInfo {
public AutoLogInfo CreateInfo { get; set; } = new();
public AutoLogInfo UpdateInfo { get; set; } = new();
}
CreateInfo is filled by AutoLogService.SetCreateInfo(entry) and UpdateInfo by SetUpdateInfo(entry), called from your change tracker.
ApplicationDbContext.cs
builder.ConfigureAutoLog();
In your change tracker, build a row per updated or deleted entry and add it to the context. CreateAutoLogItem is synchronous and returns null when the entry should not be logged.
var item = autoLogService.CreateAutoLogItem(entry);
if (item != null) Set<AutoLogItem>().Add(item);
// Optionally register an IAutoLogUserProvider to attach user info to log entries
services.AddScoped<IAutoLogUserProvider, MyCustomUserProvider>();
// Optionally register an IAutoLogRequestInfoProvider to attach request info (e.g. IP address) to log entries
services.AddScoped<IAutoLogRequestInfoProvider, MyCustomRequestInfoProvider>();
Changed properties
For updates, AutoLogItem.ChangedProperties lists the names of the changed properties, separated by commas. Values are never stored.
A property counts as changed when its current value differs from the original one, not just when EF marks it modified: Update() and Identity's UserStore.UpdateAsync mark every column modified. An owned reference (for example a translated name) is listed by its navigation name when one of its values changed. CreateInfo and UpdateInfo are never listed.
Mark a property or owned reference with [AutoLogIgnore] to leave it out. If an update changes only ignored members, CreateAutoLogItem returns null, so no row is written. If nothing differs at all (for example the state was set to Modified by hand), the row is still written, with ChangedProperties null.
[AutoLogIgnore] public DateTimeOffset LastAccess { get; set; }
The values are compared when CreateAutoLogItem is called, so call it once the entity's changes are complete, for example from SavingChanges. Changes made after the call are not listed.
Creation log
The "Added" rows for ILogChanges models are written after the save (before it, a new record's key is temporary), so they need this in the DbContext constructor:
serviceProvider.GetService<AutoLogService>()?.LogCreations(this);
Retention
The package does not delete old AutoLogs rows. Prune them from a scheduled task, for example rows older than AutoLogItem.MaxTimeSpan:
var maxDate = DateTimeOffset.UtcNow - AutoLogItem.MaxTimeSpan;
await db.Set<AutoLogItem>().Where(i => i.Time <= maxDate).ExecuteDeleteAsync();
Upgrading to 10.2
10.2 adds the ChangedProperties, RealUserId and RealUserName columns to AutoLogs, and the RealUserId and RealUserName columns to every CreateInfo/UpdateInfo owner. After upgrading, add a migration (dotnet ef migrations add AutoLog10_2).
Pruning on every logged change has been removed, so set up the retention task above if you relied on it.
GetAutoLogItem has been removed: call CreateAutoLogItem(entry) instead and skip null results.
The interfaces were replaced:
| Before 10.2 | 10.2 |
|---|---|
IHasAutoLog |
ILogChanges, IHasAutoLogInfo |
IHasCreationLog |
ILogChanges, IHasAutoLogInfo |
IHasAutoLogCreateInfo |
IHasAutoLogInfo |
IHasAutoLogUpdateInfo |
IHasAutoLogInfo |
What changes for existing models:
- Every
ILogChangesmodel now gets an "Added" row on creation (before, onlyIHasCreationLogmodels did), onceLogCreationsis called. - A model that had only
IHasAutoLogCreateInfoor onlyIHasAutoLogUpdateInfoneeds both properties, so the migration adds the missing columns to its table. - Code that checked
is IHasAutoLogto decide whether to log should checkis ILogChanges.
Showing the top 20 packages that depend on BstAutoLog.
| Packages | Downloads |
|---|---|
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
1 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
2 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
20 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
21 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
23 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
25 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
26 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
27 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
28 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
40 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
41 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
64 |
|
BstAutoLog.Web
Bomsite Auto log web extensions
|
133 |
.NET 10.0
- BstDbContextLibrary (>= 10.0.15)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.14)
| Version | Downloads | Last updated |
|---|---|---|
| 10.2.0 | 1 | 09/11/2026 |
| 10.1.14 | 3 | 06/11/2026 |
| 10.1.12 | 27 | 20/10/2026 |
| 10.1.11 | 25 | 22/09/2026 |
| 10.1.10 | 49 | 18/07/2026 |
| 10.1.9 | 137 | 14/06/2026 |
| 10.1.8 | 45 | 17/05/2026 |
| 10.1.7 | 27 | 08/05/2026 |
| 10.1.6 | 25 | 08/05/2026 |
| 10.1.5 | 30 | 03/05/2026 |
| 10.1.4 | 38 | 23/04/2026 |
| 10.1.3 | 30 | 16/04/2026 |
| 10.1.2 | 27 | 13/04/2026 |
| 10.1.1 | 27 | 13/04/2026 |
| 10.0.9 | 48 | 28/03/2026 |
| 10.0.8 | 29 | 20/03/2026 |
| 10.0.7 | 24 | 20/03/2026 |
| 10.0.6 | 28 | 20/03/2026 |
| 10.0.5 | 47 | 11/03/2026 |
| 10.0.4 | 41 | 10/02/2026 |
| 10.0.3 | 31 | 28/01/2026 |
| 10.0.2 | 54 | 12/12/2025 |
| 10.0.1 | 41 | 11/11/2025 |
| 9.1.4 | 49 | 20/10/2025 |
| 9.1.3 | 28 | 20/10/2025 |
| 9.1.2 | 36 | 15/10/2025 |
| 9.1.1 | 33 | 07/10/2025 |
| 9.1.0 | 33 | 24/09/2025 |
| 9.0.9 | 41 | 06/09/2025 |
| 9.0.8 | 46 | 15/07/2025 |
| 9.0.7 | 36 | 12/06/2025 |
| 9.0.6 | 71 | 14/05/2025 |
| 9.0.5 | 35 | 14/05/2025 |
| 9.0.4 | 51 | 09/04/2025 |
| 9.0.3 | 42 | 30/03/2025 |
| 9.0.2 | 48 | 25/03/2025 |
| 9.0.1 | 38 | 25/03/2025 |