From 7a9fe5a124fc8e897cac7aa3ff4a85f77988fc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Jasi=C5=84ski?= Date: Tue, 5 May 2026 20:05:09 +0200 Subject: [PATCH] feat: implement structured logging in KnowledgeCoordinator [MN-01] --- .../Services/KnowledgeCoordinator.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs b/src/NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs index 8b8c54b..ec709bf 100644 --- a/src/NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs +++ b/src/NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs @@ -3,6 +3,7 @@ using NexusReader.Application.Queries.Graph; using NexusReader.Application.Queries.Quiz; using NexusReader.UI.Shared.Services; using NexusReader.Application.DTOs.AI; +using Microsoft.Extensions.Logging; namespace NexusReader.UI.Shared.Services; @@ -13,6 +14,7 @@ public sealed class KnowledgeCoordinator : IDisposable private readonly IQuizStateService _quizService; private readonly IPlatformService _platformService; private readonly IReaderInteractionService _interactionService; + private readonly ILogger _logger; public event Action? OnGraphUpdated; @@ -21,13 +23,15 @@ public sealed class KnowledgeCoordinator : IDisposable IKnowledgeGraphService graphService, IQuizStateService quizService, IPlatformService platformService, - IReaderInteractionService interactionService) + IReaderInteractionService interactionService, + ILogger logger) { _knowledgeService = knowledgeService; _graphService = graphService; _quizService = quizService; _platformService = platformService; _interactionService = interactionService; + _logger = logger; _interactionService.OnNodeSelected += HandleNodeSelected; } @@ -42,7 +46,7 @@ public sealed class KnowledgeCoordinator : IDisposable { if (string.IsNullOrWhiteSpace(fullContent)) return; - Console.WriteLine("[KnowledgeCoordinator] Generating full page graph..."); + _logger.LogInformation("[KnowledgeCoordinator] Generating full page graph for tenant: {TenantId}", tenantId); _graphService.Clear(); _graphService.SetLoading(true); @@ -63,7 +67,7 @@ public sealed class KnowledgeCoordinator : IDisposable } catch (Exception ex) { - Console.WriteLine($"[KnowledgeCoordinator] Error generating graph: {ex.Message}"); + _logger.LogError(ex, "[KnowledgeCoordinator] Error generating graph for tenant: {TenantId}. Message: {ErrorMessage}", tenantId, ex.Message); } } @@ -76,6 +80,7 @@ public sealed class KnowledgeCoordinator : IDisposable public async Task RequestSummaryAndQuizAsync(string content, string tenantId = "global") { _quizService.SetHydrating(true); + _logger.LogInformation("[KnowledgeCoordinator] Requesting summary and quiz for tenant: {TenantId}", tenantId); try { var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId); @@ -90,6 +95,12 @@ public sealed class KnowledgeCoordinator : IDisposable await _platformService.VibrateSuccessAsync(); return packet; } + + _logger.LogWarning("[KnowledgeCoordinator] Failed to get summary and quiz for tenant: {TenantId}", tenantId); + } + catch (Exception ex) + { + _logger.LogError(ex, "[KnowledgeCoordinator] Error requesting summary and quiz for tenant: {TenantId}. Message: {ErrorMessage}", tenantId, ex.Message); } finally {