feat: implement structured logging in KnowledgeCoordinator [MN-01] #10
@@ -3,6 +3,7 @@ using NexusReader.Application.Queries.Graph;
|
|||||||
using NexusReader.Application.Queries.Quiz;
|
using NexusReader.Application.Queries.Quiz;
|
||||||
using NexusReader.UI.Shared.Services;
|
using NexusReader.UI.Shared.Services;
|
||||||
using NexusReader.Application.DTOs.AI;
|
using NexusReader.Application.DTOs.AI;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace NexusReader.UI.Shared.Services;
|
namespace NexusReader.UI.Shared.Services;
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
private readonly IQuizStateService _quizService;
|
private readonly IQuizStateService _quizService;
|
||||||
private readonly IPlatformService _platformService;
|
private readonly IPlatformService _platformService;
|
||||||
private readonly IReaderInteractionService _interactionService;
|
private readonly IReaderInteractionService _interactionService;
|
||||||
|
private readonly ILogger<KnowledgeCoordinator> _logger;
|
||||||
|
|
||||||
public event Action<GraphDataDto>? OnGraphUpdated;
|
public event Action<GraphDataDto>? OnGraphUpdated;
|
||||||
|
|
||||||
@@ -21,13 +23,15 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
IKnowledgeGraphService graphService,
|
IKnowledgeGraphService graphService,
|
||||||
IQuizStateService quizService,
|
IQuizStateService quizService,
|
||||||
IPlatformService platformService,
|
IPlatformService platformService,
|
||||||
IReaderInteractionService interactionService)
|
IReaderInteractionService interactionService,
|
||||||
|
ILogger<KnowledgeCoordinator> logger)
|
||||||
{
|
{
|
||||||
_knowledgeService = knowledgeService;
|
_knowledgeService = knowledgeService;
|
||||||
_graphService = graphService;
|
_graphService = graphService;
|
||||||
_quizService = quizService;
|
_quizService = quizService;
|
||||||
_platformService = platformService;
|
_platformService = platformService;
|
||||||
_interactionService = interactionService;
|
_interactionService = interactionService;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
_interactionService.OnNodeSelected += HandleNodeSelected;
|
_interactionService.OnNodeSelected += HandleNodeSelected;
|
||||||
}
|
}
|
||||||
@@ -42,7 +46,7 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(fullContent)) return;
|
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.Clear();
|
||||||
_graphService.SetLoading(true);
|
_graphService.SetLoading(true);
|
||||||
@@ -63,7 +67,7 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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")
|
public async Task<KnowledgePacket?> RequestSummaryAndQuizAsync(string content, string tenantId = "global")
|
||||||
{
|
{
|
||||||
_quizService.SetHydrating(true);
|
_quizService.SetHydrating(true);
|
||||||
|
_logger.LogInformation("[KnowledgeCoordinator] Requesting summary and quiz for tenant: {TenantId}", tenantId);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
|
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
|
||||||
@@ -90,6 +95,12 @@ public sealed class KnowledgeCoordinator : IDisposable
|
|||||||
await _platformService.VibrateSuccessAsync();
|
await _platformService.VibrateSuccessAsync();
|
||||||
return packet;
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user