Skip to content

Commit 158ba81

Browse files
committed
Megalinter fix
1 parent 17cf079 commit 158ba81

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Invoke-LogRotation {
1212
if (-not($MaxLogFiles -eq 1)) {
1313
try {
1414
# get current size of standard log file
15-
$currentSize = (Get-Item $LogFile).Length
15+
$currentSize = if (Test-Path $LogFile) { (Get-Item $LogFile).Length } else { 0 }
1616

1717
# get standard log name
1818
$logFileName = Split-Path $LogFile -Leaf
@@ -53,7 +53,7 @@ function Invoke-LogRotation {
5353

5454
# get current size of CM log file if it exists
5555
if (Test-Path $CMLogFile) {
56-
$currentCMSize = (Get-Item $CMLogFile).Length
56+
$currentCMSize = if (Test-Path $CMLogFile) { (Get-Item $CMLogFile).Length } else { 0 }
5757

5858
# get CM log name
5959
$logFileName = Split-Path $CMLogFile -Leaf

Sources/Winget-AutoUpdate/functions/Write-ToLog.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ function Write-ToLog {
7575
$Log = "#" * 65 + "`n# $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern) - $LogMsg`n" + "#" * 65
7676
Write-Host $Log -ForegroundColor $LogColor
7777
#Write log to file
78-
$Log | Out-File -FilePath $StandardLogFile -Append -Encoding Unicode
78+
$Log | Out-File -FilePath $StandardLogFile -Append
7979
}
8080
else {
8181
Write-Host $StandardLogLine -ForegroundColor $LogColor
82-
$StandardLogLine | Out-File -FilePath $StandardLogFile -Append -Encoding Unicode
82+
$StandardLogLine | Out-File -FilePath $StandardLogFile -Append
8383
}
8484

8585
# 2. Configuration Manager log format
@@ -102,7 +102,7 @@ function Write-ToLog {
102102
$CMLogLine = "<![LOG[$LogMsg]LOG]!><time=`"$time`" date=`"$date`" component=`"$Component`" context=`"`" type=`"$CMLogLevel`" thread=`"$ThreadID`" file=`"`">"
103103

104104
# Write to CM log file
105-
$CMLogLine | Out-File -FilePath $CMLogFile -Append -Encoding Unicode
105+
$CMLogLine | Out-File -FilePath $CMLogFile -Append
106106
}
107107

108108
# 3. Windows Event Log

0 commit comments

Comments
 (0)