Public/ps1/Log/Log-Apprxr.ps1

<#
    .SYNOPSIS
    Writes a log message to the configured log file for Apprxr operations.
 
    .DESCRIPTION
    The Log-Apprxr function appends a timestamped message to the log file specified in the $LogManagement.LogFolder variable. This is used for tracking events, errors, and actions within the Apprxr module. An alias 'Log' is provided for backward compatibility with scripts using the old function name.
 
    .PARAMETER msg
    The message string to write to the log file. This parameter is mandatory.
 
    .EXAMPLE
    Log-Apprxr -msg "Watcher started for folder X"
 
    .EXAMPLE
    Log "Job completed successfully"
 
    .NOTES
    The log file location and retention are managed by the LogManagement configuration.
#>

function Log-Apprxr {
    param(
        [Parameter(Mandatory=$true)][String]$msg
    )
    
    # Get the log file path from the LogManagement configuration
    $logFile = $LogManagement.LogFolder
    if (-not $logFile) {
        Write-Warning "LogManagement.LogFolder is not set. Cannot write log entry."
        return
    }
    # Format the log entry with a timestamp
    $data = (Get-date).ToString() + " "  + $msg
    # Append the log entry to the log file
    Add-Content $logFile $data

    if ($LogManament.LiveLog) {
        $result = [PSCustomObject]@{
                        success = $false
                        message = $data
                        id = $LogManament.GUID
                    }
        Get-ApprxrResult -request $deliverResult -body  ($result | ConvertTo-Json)
    }
}

$deliverResult = "api/services/app/RemoteControl/SetDeliveries"
# Alias for backward compatibility
# Allows scripts to use 'Log' as an alias for 'Log-Apprxr'
Set-Alias -Name Log -Value Log-Apprxr -Scope Global