samples: add Hello/Demo samples for most BRUTAL packages (#19)

Add samples/, a collection of single-file .NET 10 apps run with
`dotnet run <file>.cs`. Hello/ has one minimal sample per package
that has a public API, many of them headless; Demo/ has fuller
programs that combine packages into a more interesting application.

samples/README.md indexes every sample and covers the layout, error
handling and per-OS requirements.
This commit is contained in:
Rian Drake 2026-10-27 09:10:25 +13:00 • committed by GitHub
commit 7a3b72d843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,41 @@
/*
* HelloMonitorHost
*
* Starts the Monitor (a crash/log watchdog subprocess), logs a few lines to a file and prints them.
*/
#:package Ahwoo.Brutal.Monitor.Host@2026.10.2
#:package Ahwoo.Brutal.Monitor.Common@2026.10.2
// RIAN: We use this package for crash detection and dump collection at runtime.
using Brutal.Monitor.Common;
using Microsoft.Extensions.Logging;
using Monitor = Brutal.Monitor.Monitor;
Run();
static void Run()
{
var logDirectory = Path.Combine(Path.GetTempPath(), "HelloMonitor");
Directory.CreateDirectory(logDirectory);
string? logFile;
// Disposing the monitor flushes the log and stops the subprocess, so the log is read after this block.
using (var monitor = new Monitor("HelloMonitor")) // Starts the watchdog subprocess.
{
monitor.AddLogger(new LoggerOptions { LogDirectory = logDirectory });
var logger = monitor.LogProvider.CreateLogger("Hello");
logger.LogInformation("Hello from the Monitor host!");
for (var i = 0; i < 3; i++)
logger.LogWarning("Tick {Tick}", i);
logFile = monitor.LogProvider.LogFilePath;
Console.WriteLine($"Subprocess running: {monitor.SubprocessRunning}");
}
Console.WriteLine($"Log written to {logFile}:");
Console.WriteLine(File.ReadAllText(logFile!));
}