perf: use source-generated logging (LoggerMessage) for better performance and AOT compatibility

This commit is contained in:
2026-05-05 20:10:19 +02:00
parent f940df1145
commit f7948dfe62
@@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
namespace NexusReader.UI.Shared.Services; namespace NexusReader.UI.Shared.Services;
public sealed class KnowledgeCoordinator : IDisposable public sealed partial class KnowledgeCoordinator : IDisposable
{ {
private readonly IKnowledgeService _knowledgeService; private readonly IKnowledgeService _knowledgeService;
private readonly IKnowledgeGraphService _graphService; private readonly IKnowledgeGraphService _graphService;
@@ -46,7 +46,7 @@ public sealed class KnowledgeCoordinator : IDisposable
{ {
if (string.IsNullOrWhiteSpace(fullContent)) return; if (string.IsNullOrWhiteSpace(fullContent)) return;
_logger.LogInformation("[KnowledgeCoordinator] Generating full page graph for tenant: {TenantId}", tenantId); LogGeneratingGraph(tenantId);
_graphService.Clear(); _graphService.Clear();
_graphService.SetLoading(true); _graphService.SetLoading(true);
@@ -67,7 +67,7 @@ public sealed class KnowledgeCoordinator : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "[KnowledgeCoordinator] Error generating graph for tenant: {TenantId}", tenantId); LogGraphError(ex, tenantId);
} }
} }
@@ -80,7 +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); LogRequestingSummary(tenantId);
try try
{ {
var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId); var result = await _knowledgeService.GetSummaryAndQuizAsync(content, tenantId);
@@ -96,11 +96,11 @@ public sealed class KnowledgeCoordinator : IDisposable
return packet; return packet;
} }
_logger.LogWarning("[KnowledgeCoordinator] Failed to get summary and quiz for tenant: {TenantId}", tenantId); LogSummaryWarning(tenantId);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "[KnowledgeCoordinator] Error requesting summary and quiz for tenant: {TenantId}", tenantId); LogSummaryError(ex, tenantId);
} }
finally finally
{ {
@@ -119,4 +119,19 @@ public sealed class KnowledgeCoordinator : IDisposable
{ {
_interactionService.OnNodeSelected -= HandleNodeSelected; _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);
} }