changed the write-loghelper
This commit is contained in:
@@ -332,9 +332,14 @@
|
|||||||
|
|
||||||
# ─── Event Log ──────────────────────────────────────────────────
|
# ─── Event Log ──────────────────────────────────────────────────
|
||||||
if ($LogToEvent) {
|
if ($LogToEvent) {
|
||||||
|
try {
|
||||||
# 1) Ensure your custom source/log exist
|
# 1) Ensure your custom source/log exist
|
||||||
if (-not [System.Diagnostics.EventLog]::SourceExists($EventSource)) {
|
if (-not [System.Diagnostics.EventLog]::SourceExists($EventSource)) {
|
||||||
New-EventLog -LogName $EventLog -Source $EventSource
|
New-EventLog -LogName $EventLog -Source $EventSource -ErrorAction Stop
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host "[Warning] Could not create event log '$EventLog' or source '$EventSource': $($_.Exception.Message)" -ForegroundColor Yellow
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# 2) Map level to entry type
|
# 2) Map level to entry type
|
||||||
@@ -350,11 +355,10 @@
|
|||||||
-Message $fmt
|
-Message $fmt
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host "[Warning] EventLog failed: $_" -ForegroundColor Yellow
|
Write-Host "[Warning] EventLog failed: $($_.Exception.Message)" -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── PassThru ────────────────────────────────────────────────────
|
|
||||||
if ($PassThru) { return $Global:LogCache[-1] }
|
if ($PassThru) { return $Global:LogCache[-1] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user