chore: bootstrap repository foundation

Solution layout, build rules with zero-package guard, in-house test
framework, localization runtime, brand mark rasteriser with ICO/PNG
generation, Core contracts (imaging, video, domain model, TIFF reader),
Titano.Tools (make-icon, i18n, xaml-lint, package-guard) and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 08:59:40 +00:00
1 parent def3fadb6e
commit 83a54fb57b
109 files changed
+7523

No files matched your search

+116
View File
@@ -0,0 +1,116 @@
using System.Globalization;
namespace Titano.Core.Diagnostics;
public enum LogLevel
{
Trace,
Debug,
Info,
Warning,
Error,
}
/// <summary>Destination for engine log events (file logger on desktop, ILogger bridge on the server).</summary>
public interface ILogSink
{
void Write(LogLevel level, string category, string message, Exception? exception);
}
/// <summary>Tiny engine-wide logger. Core code logs through it; hosts plug in a sink.</summary>
public static class Log
{
private static ILogSink _sink = new ConsoleSink();
public static LogLevel MinimumLevel { get; set; } = LogLevel.Info;
public static void SetSink(ILogSink sink) => _sink = sink ?? throw new ArgumentNullException(nameof(sink));
public static void Debug(string category, string message) => Write(LogLevel.Debug, category, message, null);
public static void Info(string category, string message) => Write(LogLevel.Info, category, message, null);
public static void Warning(string category, string message, Exception? ex = null) => Write(LogLevel.Warning, category, message, ex);
public static void Error(string category, string message, Exception? ex = null) => Write(LogLevel.Error, category, message, ex);
public static void Write(LogLevel level, string category, string message, Exception? exception)
{
if (level < MinimumLevel) return;
try
{
_sink.Write(level, category, message, exception);
}
catch (IOException)
{
// Logging must never take the process down.
}
}
private sealed class ConsoleSink : ILogSink
{
public void Write(LogLevel level, string category, string message, Exception? exception)
{
var line = string.Create(CultureInfo.InvariantCulture, $"{DateTime.UtcNow:O} {level,-7} {category}: {message}");
if (exception is not null) line += Environment.NewLine + exception;
Console.Error.WriteLine(line);
}
}
}
/// <summary>Appends log lines to rotating files (one per day, kept for <c>retainDays</c>).</summary>
public sealed class FileLogSink : ILogSink, IDisposable
{
private readonly string _directory;
private readonly string _prefix;
private readonly int _retainDays;
private readonly Lock _gate = new();
private StreamWriter? _writer;
private DateOnly _day;
public FileLogSink(string directory, string prefix, int retainDays = 14)
{
_directory = directory;
_prefix = prefix;
_retainDays = retainDays;
Directory.CreateDirectory(directory);
}
public string CurrentPath => Path.Combine(_directory, $"{_prefix}-{_day:yyyyMMdd}.log");
public void Write(LogLevel level, string category, string message, Exception? exception)
{
lock (_gate)
{
var today = DateOnly.FromDateTime(DateTime.UtcNow);
if (_writer is null || today != _day)
{
_writer?.Dispose();
_day = today;
_writer = new StreamWriter(new FileStream(CurrentPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { AutoFlush = true };
Prune();
}
_writer.WriteLine(string.Create(CultureInfo.InvariantCulture, $"{DateTime.UtcNow:O} {level,-7} {category}: {message}"));
if (exception is not null) _writer.WriteLine(exception.ToString());
}
}
private void Prune()
{
foreach (var file in Directory.EnumerateFiles(_directory, _prefix + "-*.log"))
{
if (File.GetLastWriteTimeUtc(file) < DateTime.UtcNow.AddDays(-_retainDays))
{
try
{
File.Delete(file);
}
catch (IOException)
{
}
}
}
}
public void Dispose()
{
lock (_gate) _writer?.Dispose();
}
}