Audit Log
The audit log of StartSharp records who did what, when and from where: the inserts, updates and deletes of the records, with the old and new values of their fields, and the events of the accounts, e.g. the sign-ins, the failed sign-ins and the password changes. An administrator sees them all on the Audit Log page, and a user who may see the history of a record sees it on the History tab of its dialog.

Setup
services.AddAccountEventLog() adds the audit log, and so does services.AddAuditLog() on its own. It writes to the
aud_Events and aud_Changes tables, which a migration creates in the database of the ProAuditLog connection key; the
key falls back to ProExtensions, and then to Default. The AuditLogMigrations feature key turns the migration off.
The settings are in the AuditLog section:
| Setting | Default | |
|---|---|---|
Enabled |
true |
Whether events are written. |
RetentionDays |
0 |
How many days the events are kept, other than the ones of the accounts; 0 keeps them, as the history of a record is often needed for years. The account events keep the retention of the AccountEventLog section. |
KeepClientInfo |
true |
Whether the IP address and the user agent of the requests are kept. The ID of the request is kept anyway, as it only relates the events of a request. |
ViewPermission |
Administration:AuditLog |
The permission to see the whole log, and where the events came from in the history of a record. |
HistoryPermission |
none | A permission that the history of a record needs besides the one of its row, e.g. to show it to the managers only. |
SecurityPermission |
Administration:Security |
The permission to see the permission changes in the history of a record. |
HistoryService |
Administration/AuditLog/History |
The service that the History tab reads, or empty for no History tab. |
DataAudit |
Which entities are logged, see below. |
StartSharp's Administration:AuditLog permission can only be granted by a super admin.
Which Records Are Logged
A row with [DataAuditLog] has its inserts, updates and deletes logged:
[DataAuditLog]
public sealed class OrderRow : Row<OrderRow.RowFields>, IIdRow, INameRow
The AuditLog:DataAudit settings change which rows are logged, without changing their attributes:
"AuditLog": {
"DataAudit": {
"Mode": "OptOut",
"Exclude": [ "Northwind.Region", "job_*" ],
"Include": [ "Northwind.Customer" ]
}
}
ModeisOptInby default, which logs the rows with[DataAuditLog].OptOutlogs every row that has an ID, but the ones with[DataAuditLog(false)].IncludeandExcludename the rows that are logged, or not, whatever their attributes and the mode say: by their entity type, e.g.Northwind.Customer, or their table name, e.g.Customers, where*matches any text. A row that both name is not logged.[DataAuditLog(false)]marks a row that is never logged by default, e.g. a table of a log or a queue, so thatOptOutleaves it out. The tables of the logs, queues, sessions and tokens of the Pro features have it, and the log of a capture log (ICaptureLogRow) is treated so without it.
So the order is: Exclude, Include, the attribute of the row, a capture log, and the mode. The rows of the audit log
itself and the rows without an ID are never logged. A change of the settings applies after the application restarts.
These settings are only about the changes of the records: the events of the accounts are logged anyway.
Which Fields
The table fields of a logged row are logged, with their old and new values:
[Audited(false)]leaves a field out.[Audited(KeepValues = false)]logs that a field changed, but not its values, e.g. for a field whose values are private. The fields named like a password or a secret, e.g.PasswordHashorClientSecret, are treated so anyway.- The fields that log who inserted or updated the record and when (
IInsertLogRow,IUpdateLogRow) are not logged, as the event itself has them. - A value of a class, e.g. of a
JsonField, is kept as its JSON, and compared by it.
The value of a foreign key is kept with the name of the record it refers to, e.g. 3 with Federal Shipping. The names
are read after the transaction of the save commits, so that their queries don't hold its locks, and set on the event
then. An enum value is shown with its text in the language of the reader.
Master and Detail Records
The changes of the detail records that are saved with their master, e.g. the lines of an order, are changes of the event of the master, with the name of the line, or its type and ID when its name field isn't loaded, e.g. Order Detail 35 · Quantity. A detail record that is saved on its own is logged as an update of its master.
The Audit Log Page
The Audit Log page (Administration/AuditLog) lists the events, newest first, grouped by day, with a chart of the
activity of the period. They can be filtered by text, person, action, record and period, or to the failures and the
security events only, and exported to CSV. An event opens its details: the changes of its fields, who did it, from
which address and browser, the event as JSON, and buttons that list the events of the same request or of the same
record, and open the record.
The History of a Record
The dialog of a logged row has a History tab, with the events of its record grouped by day, the changes of each, and filters by field and by person.

The history of a record needs the permission of its row: its [HistoryPermission], else its [ReadPermission], see
Authorization, and AuditLog:HistoryPermission when it is set.
The record itself must be one that the user can retrieve, so that the rules of the row, e.g. of the tenants, apply.
In the history, the events of an account need the AccountEventLog:ViewPermission, unless they are of the user's own
account, and the permission changes need AuditLog:SecurityPermission. Where an event came from is only shown with
AuditLog:ViewPermission.
The tab is a dialog addon of the Pro extensions (AuditHistoryAddonProvider), and
the records of the events are opened with entity links.
Writing Events
A feature can write events of its own with IAuditLog:
auditLog.Write(new AuditEvent
{
Action = "Approve",
EntityType = OrderRow.Fields.RowIdentifier,
EntityId = orderId.ToString(CultureInfo.InvariantCulture),
Changes = [new AuditChange { FieldName = "Status", OldValue = "Open", NewValue = "Approved" }]
});
The user, the address and the request are filled from the current request when the event doesn't set them.
Old Logs
The events of the account event log (acc_Events) and of the data audit log of the earlier versions (DataAuditLog)
are imported into the audit log by the Audit log import background job, a part at a time, and the old tables are kept.
The old DataAuditLogBehavior doesn't write while the audit log is registered. The Audit log cleanup job removes the
events older than their retention.
On the public demo, the log shows made-up events of the employees of Northwind besides the real ones, and doesn't keep
the addresses of the visitors (AddAuditLogSampleData()).