From d0a703539a195056d21de0136aba729b9b6bb361 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 29 Jun 2025 00:38:47 -0400 Subject: [PATCH] fixed the write-loghybrid function? --- StackMonkey.ps1 | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index acd3f11..b02d9fb 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -220,11 +220,23 @@ function Write-LogHelper { } } -# Hybrid wrapper: uses your module's Write-Log if available, else falls back -if (Get-Command Write-Log -ErrorAction SilentlyContinue) { - function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent) Write-Log @PSBoundParameters } -} else { - function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent) Write-LogHelper @PSBoundParameters } +function Write-LogHybrid { + [CmdletBinding()] + param( + [Parameter(Mandatory)][string]$Message, + [ValidateSet("Info","Warning","Error","Success","General")] + [string]$Level = "Info", + [string]$TaskCategory = "GeneralTask", + [switch]$LogToEvent + ) + + # at *call* time* pick the right implementation + if ( Get-Command Write-Log -ErrorAction SilentlyContinue ) { + Write-Log @PSBoundParameters + } + else { + Write-LogHelper @PSBoundParameters + } } #endregion