Diagnostics slice of Phase 5 (builds on 5a's in-shell nav): - Structured logging: InMemoryLogStore now stores LogEntry (timestamp/level/message) + raises EntriesChanged; new ILogReader contract. A shared Serilog LoggingLevelSwitch (ILogLevelController) makes the level runtime-adjustable. ILogMaintenance exports a .zip (streams each log-*.txt with shared read so today's locked file is included), reports size, and deletes rolled files. - Log Viewer (in-shell section, Ctrl+L / Tools menu): live entries, level + text filter, per-level color (theme-safe; Information inherits body), auto-scroll, open-folder / export-.zip / clear. - Debug panel (in-shell, Tools + Settings>Advanced): verbose log dump, catalog counts + validation errors (now exposed via ICatalogProvider.ValidationErrors), system-info dump with copy. - Global crash handler: Dispatcher/AppDomain/TaskScheduler -> structured Serilog log (no sensitive data) + friendly ErrorDialog (message, error code, Copy details, Report bug, Close); re-entrancy guard; recovers dispatcher exceptions. - Report a bug (Help menu + from ErrorDialog): auto-gathered environment, export log .zip with review reminder, opens a prefilled GitHub issue. User-initiated; no auto-send (Privacy). - Settings: new Logs (level / size / open / export / clear) and Advanced (run mode / config path / open Debug panel / reset-to-defaults — preserves terms + logs) sections; ISettingsService.LogLevel persisted and applied at startup. EN/VI strings + AutomationProperties added. Dry-run deferred. 87 tests pass (store/filter/report-template/catalog-errors/settings/DI/resx); 0-warning Release build; Log Viewer smoke-verified live in dark mode. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using CommandForge.Application.Logging;
|
|
using CommandForge.Infrastructure.Logging;
|
|
using Serilog.Events;
|
|
using Serilog.Parsing;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>Tests the structured in-memory log store: mapping, ring buffer, change notification.</summary>
|
|
public sealed class InMemoryLogStoreTests
|
|
{
|
|
[Fact]
|
|
public void Emit_StoresStructuredEntry_WithMappedLevelAndMessage()
|
|
{
|
|
var store = new InMemoryLogStore();
|
|
store.Emit(Event(LogEventLevel.Warning, "hello"));
|
|
|
|
var entries = store.GetRecentEntries();
|
|
Assert.Single(entries);
|
|
Assert.Equal(LogLevel.Warning, entries[0].Level);
|
|
Assert.Equal("hello", entries[0].Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void Emit_RespectsCapacity()
|
|
{
|
|
var store = new InMemoryLogStore();
|
|
for (var i = 0; i < 1100; i++)
|
|
{
|
|
store.Emit(Event(LogEventLevel.Information, $"line {i}"));
|
|
}
|
|
|
|
Assert.True(store.GetRecentEntries().Count <= 1000);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(LogEventLevel.Verbose, LogLevel.Verbose)]
|
|
[InlineData(LogEventLevel.Debug, LogLevel.Debug)]
|
|
[InlineData(LogEventLevel.Information, LogLevel.Information)]
|
|
[InlineData(LogEventLevel.Warning, LogLevel.Warning)]
|
|
[InlineData(LogEventLevel.Error, LogLevel.Error)]
|
|
[InlineData(LogEventLevel.Fatal, LogLevel.Fatal)]
|
|
public void Emit_MapsSerilogLevel(LogEventLevel serilogLevel, LogLevel expected)
|
|
{
|
|
var store = new InMemoryLogStore();
|
|
store.Emit(Event(serilogLevel, "x"));
|
|
Assert.Equal(expected, store.GetRecentEntries()[0].Level);
|
|
}
|
|
|
|
[Fact]
|
|
public void EntriesChanged_FiresOnEmitAndClear_AndClearEmpties()
|
|
{
|
|
var store = new InMemoryLogStore();
|
|
var notifications = 0;
|
|
store.EntriesChanged += (_, _) => notifications++;
|
|
|
|
store.Emit(Event(LogEventLevel.Information, "x"));
|
|
store.Clear();
|
|
|
|
Assert.Equal(2, notifications);
|
|
Assert.Empty(store.GetRecentEntries());
|
|
}
|
|
|
|
private static LogEvent Event(LogEventLevel level, string message)
|
|
=> new(DateTimeOffset.Now, level, exception: null, new MessageTemplateParser().Parse(message), []);
|
|
}
|