Skip to content

Commit 52ce79b

Browse files
committed
Adding logging to Daily-Maintenance.ps1
1 parent f624552 commit 52ce79b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ global.json
1616
*.g.json
1717
*.g.ps1
1818
scripts/build-agents/last-execution.txt
19+
*.log

scripts/build-agents/Daily-Maintenance.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
param(
2+
[switch]$Inner
3+
)
4+
15
$ErrorActionPreference = 'Stop'
26

37
# Get the script's directory
48
$scriptDir = $PSScriptRoot
59
$lastExecutionFile = Join-Path $scriptDir "last-execution.txt"
10+
$executionLogFile = Join-Path $scriptDir "Daily-Maintenance.log"
11+
12+
# If -Inner is not specified, call this script with -Inner and use Tee-Object for logging
13+
if (-not $Inner) {
14+
& $PSCommandPath -Inner 2>&1 | Tee-Object -FilePath $executionLogFile -Append
15+
exit $LASTEXITCODE
16+
}
17+
18+
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
19+
Write-Host "[$timestamp] === Daily Maintenance Script Started ==="
20+
621

722
# Check if the script has been executed in the last 24 hours
823
$shouldExecute = $true

0 commit comments

Comments
 (0)