feat: implement structured logging in KnowledgeCoordinator [MN-01] (#10)

Reviewed-on: #10
Co-authored-by: Marek Jasiński <jasins.marek@gmail.com>
Co-committed-by: Marek Jasiński <jasins.marek@gmail.com>
This commit was merged in pull request #10.
This commit is contained in:
2026-05-05 18:12:09 +00:00
committed by Marek Jaisński
parent ef82effeac
commit 3faecbb639
6 changed files with 31 additions and 352 deletions
@@ -3,16 +3,18 @@ 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;
public sealed class KnowledgeCoordinator : IDisposable
public sealed partial class KnowledgeCoordinator : IDisposable
{
private readonly IKnowledgeService _knowledgeService;
private readonly IKnowledgeGraphService _graphService;
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...");
LogGeneratingGraph(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}");
LogGraphError(ex, tenantId);
}
}
@@ -76,6 +80,7 @@ public sealed class KnowledgeCoordinator : IDisposable
public async Task<KnowledgePacket?> RequestSummaryAndQuizAsync(string content, string tenantId = "global")
{
_quizService.SetHydrating(true);
LogRequestingSummary(tenantId);
try
{
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
@@ -90,6 +95,12 @@ public sealed class KnowledgeCoordinator : IDisposable
await _platformService.VibrateSuccessAsync();
return packet;
}
LogSummaryWarning(tenantId);
}
catch (Exception ex)
{
LogSummaryError(ex, tenantId);
}
finally
{
@@ -108,4 +119,19 @@ public sealed class KnowledgeCoordinator : IDisposable
{
_interactionService.OnNodeSelected -= HandleNodeSelected;
}
[LoggerMessage(Level = LogLevel.Information, Message = "[KnowledgeCoordinator] Generating full page graph for tenant: {TenantId}")]
private partial void LogGeneratingGraph(string tenantId);
[LoggerMessage(Level = LogLevel.Error, Message = "[KnowledgeCoordinator] Error generating graph for tenant: {TenantId}")]
private partial void LogGraphError(Exception ex, string tenantId);
[LoggerMessage(Level = LogLevel.Information, Message = "[KnowledgeCoordinator] Requesting summary and quiz for tenant: {TenantId}")]
private partial void LogRequestingSummary(string tenantId);
[LoggerMessage(Level = LogLevel.Warning, Message = "[KnowledgeCoordinator] Failed to get summary and quiz for tenant: {TenantId}")]
private partial void LogSummaryWarning(string tenantId);
[LoggerMessage(Level = LogLevel.Error, Message = "[KnowledgeCoordinator] Error requesting summary and quiz for tenant: {TenantId}")]
private partial void LogSummaryError(Exception ex, string tenantId);
}