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)