32.6 Changing a definition
You can change a definition while the log has entries. Before it saves, the Logs page lists what the change does to what is recorded, for you to confirm. Nothing is lost that the list does not name.
| Change | What happens to what is recorded |
|---|---|
| Name, description, text copy, compression | Nothing. Compression and the text copy apply to new files. |
| A column added | Older entries have no value for it, unless the application already recorded values under its key: those are kept, and read as the new column. |
| A column removed | Its values stay in the entries, and the Entries view still shows them. Its statistics are dropped. |
| A column's type changed | Old values are read as the new type where they convert, and shown as stored where not. The column's statistics are rebuilt. |
| A statistic added | It starts empty; you can rebuild it from the entries. |
| A statistic removed | What it held is dropped. |
| The level of detail, the first day of the week | Every statistic starts over; a rebuild is offered. |
| The file interval | Every entry is moved into files of the new size, which reads and writes the whole log. |
| A tighter age or size limit | Files past the limit are deleted at the next cleanup, within a minute. |
In code, PlanUpdate returns the same list without changing anything, and Update makes the change.
SetEnabled turns recording or statistics on or off, and saves the switch:
var requests = db.CustomLogs.GetDefinition("requests")!; // a copy
requests.MaxAgeOfLogFilesInDays = 30;
var plan = db.CustomLogs.PlanUpdate(requests); // nothing changes yet
foreach (var note in plan.Notes) Console.WriteLine(note);
db.CustomLogs.Update(requests, rebuildStatistics: plan.CanRebuildStatistics);
db.CustomLogs.SetEnabled("requests", log: false, statistics: null); // stop recording entries