Jump to content

MindAttic.Log: Difference between revisions

From MindAttic Docs
md2wiki: sync from MindAttic.Docs
md2wiki: sync from MindAttic.Docs
Line 3: Line 3:
One strict logging schema for every MindAttic app, written to one standalone <code>MindAttic.Log.db</code> SQLite database per app, stored under MindAttic.Vault's shared roaming root rather than any one app's own data folder.
One strict logging schema for every MindAttic app, written to one standalone <code>MindAttic.Log.db</code> SQLite database per app, stored under MindAttic.Vault's shared roaming root rather than any one app's own data folder.


[https://github.com/mindattic/MindAttic.Log/blob/main/MindAttic.Log/MindAttic.Log.csproj https://img.shields.io/badge/.NET-9.0%20and%2010.0-512BD4.svg] [https://github.com/mindattic/MindAttic.Log/blob/main/MindAttic.Log https://img.shields.io/badge/language-C%23-239120.svg] [https://github.com/mindattic/MindAttic.Log/blob/main/MindAttic.Log/MindAttic.Log.csproj https://img.shields.io/badge/version-3.0.0-blue.svg] [https://github.com/mindattic/MindAttic.Log/blob/main/MindAttic.Log.Tests https://img.shields.io/badge/tests-NUnit-brightgreen.svg] [https://github.com/mindattic/MindAttic.Log/blob/main/LICENSE https://img.shields.io/badge/license-MIT-green.svg]
[https://github.com/mindattic/MindAttic.Log/blob/main/MindAttic.Log.csproj https://img.shields.io/badge/.NET-9.0%20and%2010.0-512BD4.svg] https://img.shields.io/badge/language-C%23-239120.svg [https://github.com/mindattic/MindAttic.Log/blob/main/MindAttic.Log.csproj https://img.shields.io/badge/version-3.0.0-blue.svg] https://img.shields.io/badge/tests-NUnit-brightgreen.svg https://img.shields.io/badge/license-MIT-green.svg


== Why ==
== Why ==

Revision as of 22:15, 29 November 2026

MindAttic.Log

One strict logging schema for every MindAttic app, written to one standalone MindAttic.Log.db SQLite database per app, stored under MindAttic.Vault's shared roaming root rather than any one app's own data folder.

.NET-9.0%20and%2010.0-512BD4.svg language-C%23-239120.svg version-3.0.0-blue.svg tests-NUnit-brightgreen.svg license-MIT-green.svg

Why

Across the MindAttic ecosystem (see docs/MIGRATION.md), most apps already call ILogger<T> at their call sites but have no durable sink underneath — output goes nowhere, or to ad hoc Console.Write*/hand-rolled file writers that nobody can filter or query. MindAttic.Log replaces all of that with one package: apps keep calling ILogger<T>, and this library becomes the sink.

A flat text file is also a dead end for anything but tail/grep — there's no index, and "one giant monolithic log" degrades as it grows. Prior art (Blacklite, logdive — see docs/BIBLE.md §4) found that an embedded SQLite file beats parsing flat text for queryability while staying what a "log file" is supposed to be: one portable file, no server.

Every app gets its own standalone MindAttic.Log.db, full stop — no sharing an app's SQL Server database or its own SQLite file, and no per-app location choice. The file lives at %APPDATA%\MindAttic\Logging\<appId>\MindAttic.Log.db (resolved via MindAttic.Vault's VaultPaths.LoggingDbPath), deliberately under Vault's shared roaming root rather than the app's own %LocalAppData% — so clearing an app's local cache/data folder can never take its logs with it. Retention is row-based (delete-then-VACUUM on a schedule), not file-rolling, since the file is never replaced.

What's in this repo

  • MindAttic.Log — the shared library. LogEntry/LogSeverity (the wire schema), LogSchema (the DDL), a custom batched ILogEventSink for SQLite (WAL mode, so a Reader can query live, plus a row-based retention sweep), services.AddMindAtticLog(...) to wire it into DI, and MindAtticLogMigrator — a one-shot, explicitly-invoked tool for copying an app's historical rows out of the retired SQL Server/app-owned-SQLite tiers (see docs/MIGRATION.md).
  • MindAttic.Log.Reader — a WPF + WebView2 desktop viewer (same shape as Automata.App/KdpPublish, not Blazor) that discovers every app's standalone database under Vault's Logging bucket and lets you switch between them. Filters by date range, level, application, category, and message text.
  • docs/BIBLE.md — architecture canon: why this schema, why SQLite, the laws.
  • docs/MIGRATION.md — tracks which MindAttic apps have been audited and migrated.

Using it

services.AddMindAtticLog(o =>
{
    o.Application = "MindAttic.Launcher";
    o.DbPath = VaultPaths.LoggingDbPath("MindAttic.Launcher"); // resolved via MindAttic.Vault
});

An app that should log to SQL Server instead sets a connection string from its configuration; every such app shares the one MindAttic.Log database (created on first write if it's missing) and is told apart by the Application column:

services.AddMindAtticLog(o =>
{
    o.Application = "MindAttic.Launcher";
    o.ConnectionString = configuration.GetConnectionString("MindAttic.Log");
    // e.g. Server=localhost;Database=MindAttic.Log;Integrated Security=true;TrustServerCertificate=true
});

With no connection string the app stays on SQLite. o.Store names a registered store explicitly ("sqlite", "sqlserver") when the configuration alone shouldn't decide.

To bring an app's existing SQLite history along when it moves to SQL Server, run the migrator once with the same two values; it only reads the .db file and, re-run, copies only rows it hasn't copied yet:

await MindAtticLogMigrator.MigrateSqliteToSqlServerAsync(dbPath, connectionString);

Application code is unchanged: inject ILogger<T> and call it as usual.

Building

dotnet build MindAttic.Log.slnx
dotnet test MindAttic.Log.slnx

Part of MindAttic — see more projects at github.com/mindattic.

Pages in this repository

  • MindAttic.Log — Project Bible — MindAttic.Log is the one logging pipeline for every MindAttic app: a strict shared schema (LogEntry/MindAttic_Log) that every app writes…
  • MindAttic.Log — Migration tracker — docs/BIBLE.md §1.1 records the decision: every app now gets one standalone MindAttic.Log.db (resolved via VaultPaths.LoggingDbPath)…
  • MindAttic.Log — Release charter — The one logging pipeline for every MindAttic app: a strict schema written through ILogger<T> to a per-app MindAttic.Log.db (or the shared…
From MindAttic.Log/README.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.