From fb7830bf75e96fa784e07c51ad4775a410b4a438 Mon Sep 17 00:00:00 2001 From: "Nuno \"Omega Leo\" Diogo" Date: Sun, 14 Dec 2025 17:25:38 +0000 Subject: [PATCH] Added logging --- .../Controllers/HomeController.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/OmegaLeo.HelperLib.Web/Controllers/HomeController.cs b/OmegaLeo.HelperLib.Web/Controllers/HomeController.cs index 857b630..18b8239 100644 --- a/OmegaLeo.HelperLib.Web/Controllers/HomeController.cs +++ b/OmegaLeo.HelperLib.Web/Controllers/HomeController.cs @@ -28,31 +28,34 @@ public class HomeController : Controller if (_libraryCache != null) return; var root = GetSolutionRoot(); + _logger.LogInformation("Initializing libraries from base directory: {Root}", root); _libraryCache = new Dictionary { ["core"] = GenerateLibraryDocs( typeof(BenchmarkUtility).Assembly, - Path.Join(root, "OmegaLeo.HelperLib", "CHANGELOG.md"), + Path.Combine(root, "changelogs", "OmegaLeo.HelperLib.CHANGELOG.md"), "Core Library", "Core utilities and helper functions for general C# development", "OmegaLeo.HelperLib" ), ["changelog"] = GenerateLibraryDocs( typeof(Changelog.Models.Changelog).Assembly, - Path.Join(root, "OmegaLeo.HelperLib.Changelog", "CHANGELOG.md"), + Path.Combine(root, "changelogs", "OmegaLeo.HelperLib.Changelog.CHANGELOG.md"), "Changelog Library", "Tools for managing and generating changelogs", "OmegaLeo.HelperLib.Changelog" ), ["game"] = GenerateLibraryDocs( typeof(OmegaLeo.HelperLib.Game.Models.ConsoleCommand).Assembly, - Path.Join(root, "OmegaLeo.HelperLib.Game", "CHANGELOG.md"), + Path.Combine(root, "changelogs", "OmegaLeo.HelperLib.Game.CHANGELOG.md"), "Game Development Library", "Game development utilities for Unity and Godot", "OmegaLeo.HelperLib.Game" ) }; + + _logger.LogInformation("Initialized {Count} libraries", _libraryCache.Count); } public IActionResult Index() @@ -226,24 +229,28 @@ public class HomeController : Controller private LibraryDocumentationViewModel GenerateLibraryDocs(Assembly assembly, string changelogPath, string displayName, string description, string nugetPackageId) { - // diagnostics before calling into the library + _logger.LogInformation("Generating documentation for {Assembly}", assembly.GetName().Name); + _logger.LogInformation("Assembly location: {Location}", assembly.Location ?? ""); + _logger.LogInformation("Changelog path: {Path}", changelogPath); + _logger.LogInformation("Changelog exists: {Exists}", System.IO.File.Exists(changelogPath)); + LogDocumentationHelperInfo(); IEnumerable allDocumentation = Enumerable.Empty(); try { - // Call inside try so we can capture MethodNotFound and log diagnostics + // Pass the specific assembly to GenerateDocumentation var result = DocumentationHelperTool.GenerateDocumentation(); - // prefer safe cast / defensive assignment - allDocumentation = (result as IEnumerable) ?? - (result is IEnumerable e ? e : Enumerable.Empty()); + allDocumentation = result?.ToList() ?? Enumerable.Empty(); + + _logger.LogInformation("GenerateDocumentation returned {Count} items for {Assembly}", + allDocumentation.Count(), assembly.GetName().Name); } catch (MissingMethodException mmex) { _logger.LogError(mmex, "Missing method when calling DocumentationHelperTool.GenerateDocumentation(). Possible assembly mismatch."); InspectDocumentationHelperMethod(); - // rethrow so debugger still sees the original error ExceptionDispatchInfo.Capture(mmex).Throw(); } catch (Exception ex)