MindAttic.Log/BIBLE
MindAttic.Log — Project Bible
Single source of truth for what MindAttic.Log IS, is NOT, and the rules that keep it coherent. README.md says how to build/consume the package; this says how to think about the system.
1. The one sentence
MindAttic.Log is the one logging pipeline for every MindAttic app: a strict shared schema (LogEntry/MindAttic_Log) that every app writes through ILogger<T> as it already does, landing in one of two stores an app picks (ILogStore, LogStoreRegistry): by default its own standalone MindAttic.Log.db SQLite database — one file per app, located via MindAttic.Vault's VaultPaths.LoggingDbPath — or, when the app sets a connection string, the one shared MindAttic.Log SQL Server database. Neither store is ever the app's own SQL Server or SQLite database. A WPF + WebView2 Reader app discovers and browses both.
1.1 Superseded decision — the three-tier model (2026-10-08 → 2026-10-14)
Through 2026-10-12 this bible described a deliberate three-tier model instead: each app's rows landed on whichever storage it already had — its own SQL Server database, its own SQLite file, or (only for apps with no database at all) a rolled SQLite file in that app's own %LocalAppData%. That reasoning wasn't wrong for what it optimized for — zero extra moving parts, reuse of infrastructure an app already operated — and it shipped correctly to ~10 apps (docs/MIGRATION.md), including a live production process (Prose's Hub).
It is superseded, not corrected, by a new requirement: logs living inside an app's own database or %LocalAppData% folder are exactly as easy for a user to lose as that app's own data — cleared as "just cache," dropped with a reinstall, gone if the app's database is restored from an older backup. A standalone file under Vault's shared roaming root is harder to lose by accident, and registering every app's log location through one place (Vault) means the Reader can discover and list every app's logs itself, instead of a human pointing it at a folder/file/connection string by hand. See §4 for the resulting architecture and docs/MIGRATION.md for the Phase-2 per-app migration this requires.
2. The product promise
- One schema, two stores.
MindAttic.Log/Models/LogEntry.csandMindAttic.Log/Schema/LogSchema.csdefine the exact columns every store holds — the same shape everywhere, so a query written against one app'sMindAttic.Log.dbworks against any other's, and against the shared SQL ServerMindAttic_Logtable, unchanged. There is no third backend: a new store is anILogStoreregistered withLogStoreRegistry.Register(§4.3), and nothing else may write rows. - No call-site change. Every surveyed app already uses
ILogger<T>(see docs/MIGRATION.md).services.AddMindAtticLog(...)wires a Serilog pipeline underneath; apps delete their ad hoc writers, not their logging calls. - Still queryable, never a flat file. A flat text file with no index degrades into noise as it grows (Prose used to regex-parse daily text files just to answer "what errors happened yesterday" — see §4).
MindAttic.Log.dbis a real SQLite database: real indexes, realWHEREclauses, zero server. - Live-readable while being written. The SQLite sink runs in WAL mode specifically so MindAttic.Log.Reader can query a file while the app that owns it keeps logging to it; the SQL Server store is read with plain
SELECTs. - A write must never take the host app down. Both sinks share
MindAttic.Log/Sinks/BatchedLogSink.cs, which swallows every exception a store throws on flush or on the retention sweep, and neither sink throws at construction (M.LOGS-T78), so a full disk, a locked file or a down server never propagates into application code that was just trying to log a warning (M.LOGS-LAW-3). - Harder to lose than an app's own data. The SQLite database lives under Vault's shared roaming root (
%APPDATA%\MindAttic\Logging\<appId>\), not the app's own%LocalAppData%— clearing an app's local cache/data folder can never take its logs with it (see §1.1). The SQL Server store is a separate database, not one an app owns.
3. What it is NOT
- NOT a log aggregation server. No daemon, no ingestion API, no Seq/ELK-style central service. By default every app owns its own database file, and MindAttic.Log.Reader reads those files directly, it does not proxy them. The optional shared SQL Server
MindAttic.Logdatabase (§4.6) is a plain database that apps write to through their own sinks and the Reader queries directly; nothing sits in front of it. What changed from the superseded model (§1.1) is where the default file lives (Vault's shared roaming root, not the app's own data folder) and that it's always the same kind of file (standalone SQLite) — not whether each app still has its own. - NOT a replacement for
ILogger<T>. Apps keep callingILogger<T>/Log.Information(...)exactly as today; this package only supplies the sink underneath. - NOT a triage/issue tracker. Prose's
LogIssuetable (signature-deduped Open/Resolved/Ignored rows, recomputed against live logs on every read — see §4) is a derived view over raw logs, not a copy of them, and is intentionally out of scope for v1. A futureMindAttic.Log.Issuescould build the same idea generically on top ofMindAttic_Log, but nothing in this repo does it yet. - NOT a Blazor app. The Reader is plain WPF +
Microsoft.Web.WebView2with vanilla HTML/CSS/JS inwwwroot/, matching Automata.App and KdpPublish. BlazorWebView was considered and rejected — those two sibling apps already settled this for the ecosystem. - NOT a Vault client.
MindAtticLogOptions.DbPathandMindAtticLogOptions.ConnectionStringare plain strings this library takes as-is and never resolves itself — the host app computesDbPathviaMindAttic.Vault.Paths.VaultPaths.LoggingDbPathand reads the connection string from its own configuration before callingAddMindAtticLog(M.LOGS-LAW-2). This library has no dependency onMindAttic.Vault. - NOT a mandate to erase every other table or file that happens to hold records shaped like logs. "One pipeline" means one pipeline for general operational/diagnostic logging — the thing
ILogger<T>/Log.Information(...)calls produce. It does not mean folding a narrowly-scoped domain or compliance record intoMindAttic_Logjust because both are rows with a timestamp, and it does not mean a MindAttic.Log migration gets to restart a live production process on its own authority. Three concrete lines, each reached independently during the 2026-10-08 ecosystem-wide migration pass (docs/MIGRATION.md) and confirmed here so a future pass doesn't re-litigate them as if they were oversights:- Domain/compliance audit tables stay separate. MindAttic.Authentication's
AuthAuditLog(event type, outcome, hashed IP, user agent) and MediaButler's NDJSON file-mutationAuditLog(op/kind/from/to) are purpose-built records with their own schema and their own audience — a security reviewer, a file-recovery tool — not an operator reading application logs. Folding either intoMindAttic_Log's generic schema would be a schema regression for its real consumer, not a consolidation win. Two independent migrations reached this same conclusion. - A live production process is never restarted by a logging migration on its own authority. Prose's additive
MindAttic_Logsink (docs/MIGRATION.md) was initially committed and pushed with the already-running Hub process left untouched. It was redeployed and restarted only after being asked and getting explicit confirmation, via the Hub's own official mechanism (deploy-hub.bat), not bounced ad hoc — the same process any other code change to Prose would go through. - Interactive UI output is not a log, even when it goes to a console. MindAttic.Launcher's
AnsiConsole.MarkupLinecalls across its 17 TUI files, and MindAttic.Deploy's equivalent, are the menu/progress text a human is reading in real time — the product, not a diagnostic trail of it. Logging infrastructure gets the crash/error path (which Launcher now has); it does not get to re-route an app's own UI through a database as a side effect of "one pipeline." - A pre-existing store that backs a live, user-facing feature is not removed just because a sink now runs alongside it. Tutor's
LogStorageServicestill writesapp-logs.jsonalongsideMindAtticLogBridge(not instead of it) specifically because that file is what lets Tutor's in-app log viewer show history across an app restart today; deleting it would be a visible product behavior change (the viewer starts empty after every restart until new entries accumulate), not a logging-infrastructure decision, and nothing in this migration had the authority or the product context to make that call unilaterally. - A Phase-2 per-app migration (§1.1) may drop the old
MindAttic_Logtable it just copied — but only with the same per-app explicit confirmation Prose's restart used above, never automatically.MindAtticLogMigrator'sdropSourceparameter defaults tofalse; a caller opts in per invocation. This is not a reversal of "never alter a live store unilaterally" — it's the same rule applied: the authority comes from asking each time, not from the migration code deciding for itself.
- Domain/compliance audit tables stay separate. MindAttic.Authentication's
4. Architecture canon
4.1 Why this schema
Derived from auditing Prose's actual logging (not a guess at "industry best practice" — see the repo-wide survey this was built from, folded into docs/MIGRATION.md):
- Prose's durable tier is daily Serilog text files (
log-yyyyMMdd.txt, 14-day retention), parsed back with the regex^(.+?) \[(\w{3})\] (.+)$into{Timestamp, Level, Message, Exception}. Its live tier (an in-memory ring buffer) additionally carriesCategory— a field the file tier silently drops, because Serilog's default text template never printsSourceContext. - Prose's
LogIssuetable is a separate, derived triage layer (signature/title/status), not a copy of raw log rows — evidence that "logs" and "the queryable index over logs" are different concerns, which is exactly the split this repo keeps:MindAttic_Logis raw rows; a future issues table would be derived from it, not the other way around.
LogEntry is Prose's three tiers reconciled into one row shape: TimestampUtc, Level, Application (new — Prose is single-app, MindAttic.Log is not), Category (fixes the file-tier gap), Message, MessageTemplate (new — lets a Reader group by shape, not exact text), Exception, PropertiesJson (new — keeps the column count fixed regardless of what a call site logs), CorrelationId (new — cross-call tracing), MachineName.
4.2 Why SQLite, not text, and why standalone, not shared
Researched explicitly for this decision (not assumed): SQLite as a queryable, dependency-free log store is validated prior art, not a novel idea here — Blacklite (a JVM diagnostic appender) reports SQL queries beating flat-file parsing and a vacuumed SQLite database staying only slightly larger than the equivalent text log; logdive indexes JSON/logfmt/plain-text logs into local SQLite with no daemon; and the general guidance from that research — promote the columns you actually filter on (timestamp, level, application, category) into real indexed columns, keep WAL on for concurrent readers — is exactly what MindAttic.Log/Schema/LogSchema.cs and MindAttic.Log/Sinks/MindAtticSqliteSink.cs do.
The file is never rolled or replaced (unlike the superseded model's monthly MindAttic.Log.<yyyy-MM>.db rotation, §1.1) — it's one MindAttic.Log.db for the life of the app. Retention is therefore row-based: BatchedLogSink runs a retention timer (every 24 hours) and MindAtticSqliteSink deletes rows older than RetainedDays (default 365; zero or negative disables the sweep) and runs VACUUM to reclaim the freed space, replacing the old model's file-count pruning.
The location — %APPDATA%\MindAttic\Logging\<appId>\MindAttic.Log.db, via MindAttic.Vault.Paths.VaultPaths.LoggingDbPath(appId) — is deliberately Vault's shared roaming root, not the app's own %LocalAppData%, per §1.1/§2. Logging is documented as a Vault bucket (../MindAttic.Vault/docs/BIBLE.md §9) but is not a credential bucket: no providers.json, no IConfiguration projection — just a shared, conventionally-named folder.
4.3 Store registry and sink architecture
+----------------------------------------------------------+ | ILogger<T> call sites (unchanged) | +----------------------------------------------------------+ | services.AddMindAtticLog(options) or | | LoggerConfiguration.WriteToMindAtticLog(options) | +----------------------------------------------------------+ | LogStoreRegistry.Resolve(options.EffectiveStore) | +----------------------------------------------------------+ | "sqlite" (default): SqliteLogStore | | MindAtticSqliteSink -> options.DbPath | | %APPDATA%\MindAttic\Logging\<appId>\MindAttic.Log.db | +----------------------------------------------------------+ | "sqlserver": SqlServerLogStore | | MindAtticSqlServerSink -> options.ConnectionString | | shared database MindAttic.Log, table MindAttic_Log | +----------------------------------------------------------+ | both sinks derive from BatchedLogSink | | (batch, flush timer, retention timer, swallow failures) | +----------------------------------------------------------+
ILogStore (MindAttic.Log/Stores/ILogStore.cs) is the seam: a Name and CreateSink(options), which validates the settings that store needs and throws InvalidOperationException when one is missing. LogStoreRegistry keys stores by case-insensitive name. SqliteLogStore ("sqlite", the default, needs DbPath) and SqlServerLogStore ("sqlserver", needs ConnectionString) are registered from the start; Register adds or replaces one, and Resolve throws for an unregistered name. LoggerConfigurationExtensions.WriteToMindAtticLog resolves MindAtticLogOptions.EffectiveStore: the Store option when set, otherwise "sqlserver" when ConnectionString is set, otherwise "sqlite". ServiceCollectionExtensions.AddMindAtticLog wraps the same call and registers ILogger<T>.
MindAttic.Log/Sinks/BatchedLogSink.cs holds what both sinks share: events queue in memory and are written as one batch at batchSize (200 by default), on a flush timer (2 seconds) and on dispose; a second timer sweeps old rows. A store's sink supplies only how a batch is written and how old rows are pruned. Any exception is swallowed there and the batch is dropped (M.LOGS-LAW-3). Severity mapping between LogSeverity, Serilog and Microsoft levels is MindAttic.Log/Models/LogSeverityMap.cs (M.LOGS-T67).
The SQLite sink creates the folder, turns on WAL and creates MindAttic_Log best-effort at construction and retries on every flush, so a path that cannot be created yet never fails the host (M.LOGS-T78). There is no separate migration or startup step: every MindAttic.Log.db is this library's own file, never shared with anything else.
4.4 Migrating existing historical data
Apps already migrated onto the superseded three-tier model (docs/MIGRATION.md) have real MindAttic_Log history sitting in a SQL Server table or inside their own app-owned SQLite file. MindAttic.Log/Migration/MindAtticLogMigrator.cs is the one-shot tool each app's own Phase-2 pass runs once: MigrateFromSqlServerAsync/MigrateFromSqliteAsync copy that app's rows into its new standalone MindAttic.Log.db (idempotent by a per-Application TimestampUtc watermark, so a re-run after a partial failure doesn't duplicate rows), and optionally drop the source table — gated behind an explicit dropSource: true the caller must pass per invocation (see §3's confirmed exception). This never runs automatically; see docs/MIGRATION.md for the per-app rollout. The work is done by MindAttic.Log/Migration/LegacyLogMigrator.cs.
MindAtticLogMigrator.MigrateSqliteToSqlServerAsync is the third entry point and goes the other way: it copies an app's standalone MindAttic.Log.db into the shared SQL Server database (§4.6) when the app moves onto the "sqlserver" store. It only reads the source file, and MindAttic.Log/Migration/SqliteToSqlServerMigrator.cs writes through the SQL Server sink's own INSERT. All three are idempotent by a per-Application watermark.
4.5 Reader architecture
MindAttic.Log.Reader is a single-pane WPF Microsoft.Web.WebView2 host (no AutoWebNav — that package drives/records a third-party page under automation, which a read-only log viewer never does). LogQueryService is the only thing that touches storage, and it does so through one ILogStoreReader per store (MindAttic.Log.Reader/Services/ILogStoreReader.cs), mirroring ILogStore:
SqliteLogStoreReaderlists every subfolder of Vault'sLoggingbucket that has aMindAttic.Log.dband opens a chosen app's database read-only.SqlServerLogStoreReaderlists the apps of each SQL Server database named in the Vault setting "SQL Server log databases" (ReaderSettings.SqlServerDatabases, one connection string per line; a string naming no database getsMindAttic.Log) and queries them withSELECT.
DiscoverApps() merges every reader's LogSources (one app in one store) and drives the app switcher in wwwroot/; a reader whose listing throws is skipped and logged, and a SQL Server database that is down contributes no apps (M.LOGS-T72). The page never sees a connection string: MindAttic.Log.Reader/Services/ReaderPage.cs sends it only a key, store, app id and label, and the host looks the source up by key (M.LOGS-T73). MainWindow is the JS↔C# bridge (WebMessageReceived in, ExecuteScriptAsync out), exactly the pattern Automata.App and KdpPublish already use.
4.6 The shared SQL Server store
An app moves onto it by setting MindAtticLogOptions.ConnectionString (Store = "sqlserver" also selects it, but SqlServerLogStore.CreateSink throws without a connection string); SqlServerLogStore then builds a MindAtticSqlServerSink (MindAttic.Log/Sinks/MindAtticSqlServerSink.cs). Every app that does so writes into one database, MindAtticSqlServerSink.DefaultDatabase = MindAttic.Log, used when the connection string names none, in the same MindAttic_Log table whose Application column tells apps apart. Connection strings in docs and settings use Integrated Security or a Vault-resolved secret, never an inline password.
The sink creates the database (through master) and the table on first flush when either is missing. Retention deletes only the writing app's own rows (Application = @application), so one app's RetainedDays never trims another's history. Moving an existing app's history in is MigrateSqliteToSqlServerAsync (§4.4). As of 2026-12-01 no consuming app sets ConnectionString (docs/MIGRATION.md), so the store is shipped in the package but not yet used by a consumer.
5. The Laws
This project inherits the org-wide laws in MindAttic.HouseRules.md by reference. Directly load-bearing:
- HOUSE-LAW-1 — whole-number versioning.
- HOUSE-LAW-3 — credentials resolve through MindAttic.Vault; see M.LOGS-LAW-2.
- HOUSE-LAW-6 — one engine, many front doors (every destination goes through the same
AddMindAtticLog/WriteToMindAtticLogpath). - HOUSE-LAW-8 — done is verified, not asserted.
- HOUSE-LAW-10 — commit directly to main.
Project-specific laws:
One schema, no per-app drift.
No consumer app adds its own columns to MindAttic_Log or writes to it outside this library's sinks. A need for an app-specific field is a conversation about extending LogSchema for everyone (see PropertiesJson for the escape hatch that exists precisely so this law doesn't get broken under pressure), not a local fork of the table.
This library resolves no Vault locations itself.
MindAtticLogOptions.DbPath and MindAtticLogOptions.ConnectionString are plain strings the host supplies; MindAttic.Log never reads %APPDATA%, Key Vault, or any other config/secret source itself, and has no package dependency on MindAttic.Vault. The host computes DbPath via VaultPaths.LoggingDbPath(appId) before calling AddMindAtticLog. (MindAttic.Log/MindAtticLogOptions.cs.) MindAtticLogMigrator's source and destination follow the same rule: the caller already has them, the migrator never resolves them.
A logging failure never becomes an application failure.
Every sink catches and swallows its own storage-layer exceptions: BatchedLogSink wraps WriteBatch and Prune in a catch-all, because a full disk (IOException), a locked file (UnauthorizedAccessException) and a down server (SqlException) are different types. A full disk, a locked file or an unreachable server must never throw out of an ILogger.LogInformation(...) call site. (MindAttic.Log/Sinks/BatchedLogSink.cs.)
The Reader never writes.
MindAttic.Log.Reader opens SQLite connections in SqliteOpenMode.ReadOnly and issues SELECT only, against SQL Server as well. It is a viewer, not a second writer that could race the app's own sink. (MindAttic.Log.Reader/Services/SqliteLogStoreReader.cs, SqlServerLogStoreReader.cs.)
6. Glossary
- Standalone database — an app's one
MindAttic.Log.db, the default store (see §1.1 for the superseded SQL Server / app-owned-SQLite / rolled-file model). - Store — an
ILogStoreregistered inLogStoreRegistryunder a name:"sqlite"or"sqlserver". - Shared SQL Server database — the one
MindAttic.Logdatabase the"sqlserver"store writes to (§4.6). - Wire schema — the column set in
MindAttic.Log/Schema/LogSchema.cs. Loggingbucket — the Vault roaming-root folder (%APPDATA%\MindAttic\Logging\) every app's standalone database lives under, one subfolder per app id; seeVaultPaths.LoggingDbPath.- Sink —
MindAtticSqliteSinkorMindAtticSqlServerSink, the SerilogILogEventSinks (both derive fromBatchedLogSink) that persist aLogEntryrow. - Migrator —
MindAtticLogMigrator, the one-shot tool that copies an app's historical rows out of the superseded tiers, or from itsMindAttic.Log.dbinto the shared SQL Server database (§4.4, docs/MIGRATION.md). - Reader —
MindAttic.Log.Reader, the WPF + WebView2 viewer; discovers apps through oneILogStoreReaderper store (theLoggingbucket for SQLite, the "SQL Server log databases" setting for SQL Server) instead of a manual folder/file picker.
7. Verified state
Cross-read against the code on 2026-12-01 (M.LOGS-T76), not a test run:
MindAttic.Log4.0.0 is packed toC:\LocalNuGet(M.LOGS-T43). It ships both stores, the registry,BatchedLogSinkand the three migrations.- Every consuming app is still on 3.0.0 and on the
"sqlite"store; none setsConnectionStringorStore. docs/MIGRATION.md has the per-app list. - The Reader lists apps from SQLite files and, when configured, SQL Server databases; it is not yet exercised against a consumer writing to SQL Server, because none does.