From ec5a49ef61c96aeba8f89ede7d48492dca11b1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Mon, 29 Dec 2025 16:31:34 +0100 Subject: [PATCH] Make ILogger optional in LocalResourceUrlManager --- .../ResourceManagement/LocalResourceUrlManager.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Framework/Framework/ResourceManagement/LocalResourceUrlManager.cs b/src/Framework/Framework/ResourceManagement/LocalResourceUrlManager.cs index b4149497d1..6612b5996c 100644 --- a/src/Framework/Framework/ResourceManagement/LocalResourceUrlManager.cs +++ b/src/Framework/Framework/ResourceManagement/LocalResourceUrlManager.cs @@ -14,7 +14,7 @@ namespace DotVVM.Framework.ResourceManagement { public class LocalResourceUrlManager : ILocalResourceUrlManager { - private readonly ILogger logger; + private readonly ILogger? logger; private readonly IResourceHashService hasher; private readonly RouteBase resourceRoute; private readonly DotvvmResourceRepository resources; @@ -22,7 +22,7 @@ public class LocalResourceUrlManager : ILocalResourceUrlManager private readonly bool requireResourceVersionHash; private readonly bool allowResourceVersionHash; - public LocalResourceUrlManager(DotvvmConfiguration configuration, IResourceHashService hasher, ILogger logger) + public LocalResourceUrlManager(DotvvmConfiguration configuration, IResourceHashService hasher, ILogger? logger = null) { this.resourceRoute = new DotvvmRoute( url: HostingConstants.ResourceRouteName + "-{name}/{fileName}", @@ -89,7 +89,7 @@ protected virtual string GetVersionHash(ILocalResourceLocation location, IDotvvm { if (requireResourceVersionHash && GetVersionHash(location, context, name) != hash) { // check if the resource matches so that nobody can guess the url by chance - logger.LogInformation("Requested resource {name} with hash '{hash}' does not match the expected hash '{expectedHash}' and the request was rejected.", name, hash, GetVersionHash(location, context, name)); + logger?.LogInformation("Requested resource {name} with hash '{hash}' does not match the expected hash '{expectedHash}' and the request was rejected.", name, hash, GetVersionHash(location, context, name)); return null; } @@ -99,7 +99,7 @@ protected virtual string GetVersionHash(ILocalResourceLocation location, IDotvvm return TryLoadAlternativeFile(name, fileName, resource, context); } - logger.LogInformation("Requested resource '{name}' not found.", name); + logger?.LogInformation("Requested resource '{name}' not found.", name); return null; } @@ -120,7 +120,7 @@ private static bool IsAllowedFileName(string name) { if (!IsAllowedFileName(fileName)) { - logger.LogWarning("Requested additional file '{fileName}' for resource {resourceName} is not allowed.", fileName, name); + logger?.LogWarning("Requested additional file '{fileName}' for resource {resourceName} is not allowed.", fileName, name); return null; }