From 4c5321958a766eaf5f1d6aabcc8728d1029c93b2 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 31 Mar 2025 20:55:57 +0200 Subject: [PATCH] Logger --- Caches/FileDbCache/FileDbCache.cs | 7 ++----- Caches/SQLiteCache/SQLiteCache.cs | 7 ++----- MapControl/Shared/ImageFileCache.cs | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Caches/FileDbCache/FileDbCache.cs b/Caches/FileDbCache/FileDbCache.cs index d2c5ae4a..436e4ac4 100644 --- a/Caches/FileDbCache/FileDbCache.cs +++ b/Caches/FileDbCache/FileDbCache.cs @@ -43,11 +43,6 @@ namespace MapControl.Caching public FileDbCache(FileDbCacheOptions options, ILoggerFactory loggerFactory = null) { - if (loggerFactory != null) - { - logger = loggerFactory.CreateLogger(); - } - var path = options.Path; if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(Path.GetExtension(path))) @@ -55,6 +50,8 @@ namespace MapControl.Caching path = Path.Combine(path ?? "", "TileCache.fdb"); } + logger = loggerFactory?.CreateLogger(); + try { fileDb.Open(path); diff --git a/Caches/SQLiteCache/SQLiteCache.cs b/Caches/SQLiteCache/SQLiteCache.cs index af0b3549..5923f468 100644 --- a/Caches/SQLiteCache/SQLiteCache.cs +++ b/Caches/SQLiteCache/SQLiteCache.cs @@ -39,11 +39,6 @@ namespace MapControl.Caching public SQLiteCache(SQLiteCacheOptions options, ILoggerFactory loggerFactory = null) { - if (loggerFactory != null) - { - logger = loggerFactory.CreateLogger(); - } - var path = options.Path; if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(Path.GetExtension(path))) @@ -64,6 +59,8 @@ namespace MapControl.Caching command.ExecuteNonQuery(); } + logger = loggerFactory?.CreateLogger(); + logger?.LogInformation("Opened database {path}", path); if (options.ExpirationScanFrequency > TimeSpan.Zero) diff --git a/MapControl/Shared/ImageFileCache.cs b/MapControl/Shared/ImageFileCache.cs index d73e430e..c5c3bf8b 100644 --- a/MapControl/Shared/ImageFileCache.cs +++ b/MapControl/Shared/ImageFileCache.cs @@ -43,16 +43,13 @@ namespace MapControl.Caching public ImageFileCache(ImageFileCacheOptions options, ILoggerFactory loggerFactory = null) { - if (loggerFactory != null) - { - logger = loggerFactory.CreateLogger(); - } - var path = options.Path; rootDirectory = new DirectoryInfo(!string.IsNullOrEmpty(path) ? path : "TileCache"); rootDirectory.Create(); + logger = loggerFactory?.CreateLogger(); + logger?.LogInformation("Started in {name}", rootDirectory.FullName); var memoryCacheOptions = new MemoryDistributedCacheOptions();