From 5d8e3263c6ea8b33d410094404e9688f32f74303 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Wed, 9 Jul 2025 16:36:19 -0400 Subject: [PATCH] fixed global logs --- StackMonkey.ps1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index a9b7a82..22d637d 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -193,9 +193,9 @@ $Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit' # Initialize a global in-memory log cache - if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) - { - $Global:LogCache = [System.Collections.ArrayList]::new() + + if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) { + $Global:LogCache = [System.Collections.ArrayList]::new() } #endregion global variables @@ -312,12 +312,17 @@ Write-Host $fmt -ForegroundColor $color # ─── In-Memory Cache ───────────────────────────────────────────── - if (-not $Global:LogCache) { $Global:LogCache = [System.Collections.ArrayList]::new() } + + # ─── In-Memory Cache ───────────────────────────────────────────── + if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) { + $Global:LogCache = [System.Collections.ArrayList]::new() + } $Global:LogCache.Add([pscustomobject]@{ Timestamp = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss') Level = $Level Message = $fmt }) | Out-Null + # ─── File Logging ──────────────────────────────────────────────── if ($PSBoundParameters.LogFile) {