From e0ba6acd60a88520cc1fea771de19ed2fa61c1c5 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 19 Sep 2023 22:56:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=97=A5=E5=BF=97=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E5=A4=B1=E8=B4=A5=E9=80=A0=E6=88=90=E7=9A=84=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Common/Log/Logger.cs | 49 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/N_m3u8DL-RE.Common/Log/Logger.cs b/src/N_m3u8DL-RE.Common/Log/Logger.cs index 775403f..897f086 100644 --- a/src/N_m3u8DL-RE.Common/Log/Logger.cs +++ b/src/N_m3u8DL-RE.Common/Log/Logger.cs @@ -70,32 +70,39 @@ namespace N_m3u8DL_RE.Common.Log private static void HandleLog(string write, string subWrite = "") { - if (subWrite == "") + try { - AnsiConsole.MarkupLine(write); - } - else - { - AnsiConsole.Markup(write); - Console.WriteLine(subWrite); - } - if (IsWriteFile && File.Exists(LogFilePath)) - { - var plain = write.RemoveMarkup() + subWrite.RemoveMarkup(); - try + if (subWrite == "") { - //进入写入 - LogWriteLock.EnterWriteLock(); - using (StreamWriter sw = File.AppendText(LogFilePath)) + AnsiConsole.MarkupLine(write); + } + else + { + AnsiConsole.Markup(write); + Console.WriteLine(subWrite); + } + if (IsWriteFile && File.Exists(LogFilePath)) + { + var plain = write.RemoveMarkup() + subWrite.RemoveMarkup(); + try { - sw.WriteLine(plain); + //进入写入 + LogWriteLock.EnterWriteLock(); + using (StreamWriter sw = File.AppendText(LogFilePath)) + { + sw.WriteLine(plain); + } + } + finally + { + //释放占用 + LogWriteLock.ExitWriteLock(); } } - finally - { - //释放占用 - LogWriteLock.ExitWriteLock(); - } + } + catch (Exception) + { + Console.WriteLine("Failed to write: " + write); } }