diff --git a/src/N_m3u8DL-RE.Common/Log/Logger.cs b/src/N_m3u8DL-RE.Common/Log/Logger.cs index 775403f1..897f086d 100644 --- a/src/N_m3u8DL-RE.Common/Log/Logger.cs +++ b/src/N_m3u8DL-RE.Common/Log/Logger.cs @@ -70,32 +70,39 @@ private static string GetCurrTime() private static void HandleLog(string write, string subWrite = "") { - if (subWrite == "") - { - AnsiConsole.MarkupLine(write); - } - else - { - AnsiConsole.Markup(write); - Console.WriteLine(subWrite); - } - if (IsWriteFile && File.Exists(LogFilePath)) + try { - var plain = write.RemoveMarkup() + subWrite.RemoveMarkup(); - try + if (subWrite == "") { - //进入写入 - LogWriteLock.EnterWriteLock(); - using (StreamWriter sw = File.AppendText(LogFilePath)) - { - sw.WriteLine(plain); - } + AnsiConsole.MarkupLine(write); } - finally + else { - //释放占用 - LogWriteLock.ExitWriteLock(); + AnsiConsole.Markup(write); + Console.WriteLine(subWrite); } + if (IsWriteFile && File.Exists(LogFilePath)) + { + var plain = write.RemoveMarkup() + subWrite.RemoveMarkup(); + try + { + //进入写入 + LogWriteLock.EnterWriteLock(); + using (StreamWriter sw = File.AppendText(LogFilePath)) + { + sw.WriteLine(plain); + } + } + finally + { + //释放占用 + LogWriteLock.ExitWriteLock(); + } + } + } + catch (Exception) + { + Console.WriteLine("Failed to write: " + write); } }