feat: implement structured logging in KnowledgeCoordinator [MN-01]

This commit is contained in:
2026-05-05 20:05:09 +02:00
parent ef82effeac
commit 7a9fe5a124
@@ -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<KnowledgeCoordinator> _logger;
public event Action<GraphDataDto>? OnGraphUpdated;
@@ -21,13 +23,15 @@ public sealed class KnowledgeCoordinator : IDisposable
IKnowledgeGraphService graphService,
IQuizStateService quizService,
IPlatformService platformService,
IReaderInteractionService interactionService)
IReaderInteractionService interactionService,
ILogger<KnowledgeCoordinator> 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<KnowledgePacket?> 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
{