mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
samples: add Hello/Demo samples for most BRUTAL packages
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:
parent
a25cdf80b2
commit
b0c9fd9cdc
1 changed files with 4599 additions and 1 deletions
41
samples/Hello/HelloMonitorHost.cs
Normal file
41
samples/Hello/HelloMonitorHost.cs
Normal 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!));
|
||||
}
|
||||
Loading…
Reference in a new issue