From 2fd6e68025d4b987cfde52b8402038ca34116876 Mon Sep 17 00:00:00 2001
From: Moli <13026959681@163.com>
Date: 星期日, 03 五月 2026 13:00:05 +0800
Subject: [PATCH] merge

---
 src/Moli.Desktop/Diagnostics/DiagnosticsService.cs |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs b/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs
index f1e6b58..093219d 100644
--- a/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs
+++ b/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs
@@ -33,13 +33,13 @@
             Properties = properties ?? new Dictionary<string, string>()
         };
 
+        _logger.Log(MapLevel(severity), "{Code}: {Message}", code, message);
         lock (_gate)
         {
             _entries.Add(entry);
+            AppendLog(entry);
         }
 
-        _logger.Log(MapLevel(severity), "{Code}: {Message}", code, message);
-        AppendLog(entry);
         return entry;
     }
 
@@ -59,7 +59,18 @@
             line += " " + string.Join(";", entry.Properties.Select(p => $"{p.Key}={p.Value}"));
         }
 
-        File.AppendAllText(_logFile, line + Environment.NewLine, Encoding.UTF8);
+        try
+        {
+            File.AppendAllText(_logFile, line + Environment.NewLine, Encoding.UTF8);
+        }
+        catch (IOException)
+        {
+            _logger.LogWarning("Failed to append diagnostic log file because it is currently unavailable.");
+        }
+        catch (UnauthorizedAccessException)
+        {
+            _logger.LogWarning("Failed to append diagnostic log file because access was denied.");
+        }
     }
 
     private static LogLevel MapLevel(DiagnosticSeverity severity) => severity switch

--
Gitblit v1.9.1