Update smart_shutdown.ps1 v0.2

每次写日志时,都重新根据当前日期确定日志文件名
This commit is contained in:
2025-06-11 23:42:19 +08:00
committed by GitHub
parent 7ed04262c3
commit 4b8e3da812

View File

@@ -34,7 +34,7 @@
# 日志配置 # 日志配置
[string]$LogDirectory = Join-Path -Path $PSScriptRoot -ChildPath "logs" [string]$LogDirectory = Join-Path -Path $PSScriptRoot -ChildPath "logs"
[string]$LogFile = Join-Path -Path $LogDirectory -ChildPath "network_monitor_$(Get-Date -Format 'yyyyMMdd').log" #[string]$LogFile = Join-Path -Path $LogDirectory -ChildPath "network_monitor_$(Get-Date -Format 'yyyyMMdd').log"
[int]$MaxLogDays = 30 [int]$MaxLogDays = 30
# ================================================= # =================================================
@@ -52,6 +52,11 @@ function Write-Log {
[string]$Message [string]$Message
) )
# ===================== V0.2update =====================
# 每次写日志时,都重新根据当前日期确定日志文件名
$LogFile = Join-Path -Path $LogDirectory -ChildPath "network_monitor_$(Get-Date -Format 'yyyyMMdd').log"
# ====================================================
$logTimestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $logTimestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "[$logTimestamp] [$Level] $Message" $logEntry = "[$logTimestamp] [$Level] $Message"
@@ -231,4 +236,4 @@ while ($true) {# 测试网络连接
Start-Sleep -Seconds $NormalPingInterval Start-Sleep -Seconds $NormalPingInterval
} }
} }
} }