+function Rotate-Log {\r
+ if($keepLogs -le 0) {\r
+ return\r
+ }\r
+ \r
+ $keepLogsCount = $keepLogs\r
+ \r
+ Get-ChildItem $logDir -File | Where-Object {($_.Name -ne "$currMonth.log") -and ($_.Name -match "^\d{4,}-\d{2}\.log$")} | Sort-Object -Descending |\r
+ Foreach-Object {\r
+ if($keepLogsCount -ge 0) {\r
+ $keepLogsCount--\r
+ }\r
+ \r
+ if($keepLogsCount -eq -1) {\r
+ Write-Log "Deleting log file $($_.FullName)" -Path $logFile -Level Info\r
+ Remove-Item -Force $_.FullName\r
+ }\r
+ }\r
+}\r
+\r