From 606db68dbb9090ee615ef1d89e6749c2e1670549 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sun, 30 Jun 2024 18:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91=20(#412)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Common/Log/Logger.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/N_m3u8DL-RE.Common/Log/Logger.cs b/src/N_m3u8DL-RE.Common/Log/Logger.cs index eafbdc4..a5d69b1 100644 --- a/src/N_m3u8DL-RE.Common/Log/Logger.cs +++ b/src/N_m3u8DL-RE.Common/Log/Logger.cs @@ -45,21 +45,20 @@ namespace N_m3u8DL_RE.Common.Log Directory.CreateDirectory(logDir); } - LogFilePath = Path.Combine(logDir, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff") + ".log"); - //若文件存在则加序号 + var now = DateTime.Now; + LogFilePath = Path.Combine(logDir, now.ToString("yyyy-MM-dd_HH-mm-ss-fff") + ".log"); int index = 1; var fileName = Path.GetFileNameWithoutExtension(LogFilePath); + string init = "LOG " + now.ToString("yyyy/MM/dd") + Environment.NewLine + + "Save Path: " + Path.GetDirectoryName(LogFilePath) + Environment.NewLine + + "Task Start: " + now.ToString("yyyy/MM/dd HH:mm:ss") + Environment.NewLine + + "Task CommandLine: " + Environment.CommandLine; + init += $"{Environment.NewLine}{Environment.NewLine}"; + //若文件存在则加序号 while (File.Exists(LogFilePath)) { LogFilePath = Path.Combine(Path.GetDirectoryName(LogFilePath)!, $"{fileName}-{index++}.log"); } - - string now = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); - string init = "LOG " + DateTime.Now.ToString("yyyy/MM/dd") + Environment.NewLine - + "Save Path: " + Path.GetDirectoryName(LogFilePath) + Environment.NewLine - + "Task Start: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + Environment.NewLine - + "Task CommandLine: " + Environment.CommandLine; - init += $"{Environment.NewLine}{Environment.NewLine}"; File.WriteAllText(LogFilePath, init, Encoding.UTF8); } catch (Exception ex)