39 Star 222 Fork 51

chuanjiao10 / kasini3000

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
k_写log.ps1 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
#建议保存编码为:bom头 + utf8
param
(
[Alias("LogString")][string]$被写入的log内容 = ''
)
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
& 'c:\ProgramData\kasini3000\0k_source.ps1'
}
if ($IsLinux -eq $True)
{
& '/etc/kasini3000/0k_source.ps1'
}
$父目录 = Split-Path -LiteralPath $global:卡死你3000日志文件全路径
if (Test-Path -LiteralPath $父目录)
{
if (Test-Path -LiteralPath $global:卡死你3000日志文件全路径)
{
$private:temp = Get-Item -LiteralPath $global:卡死你3000日志文件全路径
if ($private:temp.Length -gt 128mb)
{
$日期 = Get-Date -Format 'yyyyMMdd_HHmm'
$新文件名 = "${父目录}/${日期}"
Move-Item -LiteralPath $global:卡死你3000日志文件全路径 -Destination $新文件名 -Force
Start-Sleep -Seconds 2
if ($PSVersionTable.psversion.major -lt 6)
{
Set-Content -LiteralPath $global:卡死你3000日志文件全路径 -Value '' -Encoding utf8
}
else
{
Set-Content -LiteralPath $global:卡死你3000日志文件全路径 -Value '' -Encoding utf8bom
}
}
}
else
{
if ($PSVersionTable.psversion.major -lt 6)
{
Set-Content -LiteralPath $global:卡死你3000日志文件全路径 -Value '' -Encoding utf8
}
else
{
Set-Content -LiteralPath $global:卡死你3000日志文件全路径 -Value '' -Encoding utf8bom
}
}
$时间 = Get-Date -Format F
$输出信息 = "$时间 $被写入的log内容"
if (Test-Path -LiteralPath "${PSScriptRoot}/bf并发锁写txt_v15.ps1")
{
& "${PSScriptRoot}/bf并发锁写txt_v15.ps1" -写入文件名 $global:卡死你3000日志文件全路径 -写入值 $输出信息
}
else
{
if ($PSVersionTable.psversion.major -lt 6)
{
Add-Content -LiteralPath $global:卡死你3000日志文件全路径 -Value $输出信息 -Encoding utf8
}
else
{
Add-Content -LiteralPath $global:卡死你3000日志文件全路径 -Value $输出信息 -Encoding utf8bom
}
}
}
else
{
Write-Error '找不到日志文件目录,请【重新安装】或【升级】'
exit 1
}
exit 0
PowerShell
1
https://gitee.com/chuanjiao10/kasini3000.git
git@gitee.com:chuanjiao10/kasini3000.git
chuanjiao10
kasini3000
kasini3000
master

搜索帮助