Public/Send-ConnectorLog.ps1

<#
.SYNOPSIS
    Sends a log entry to the Fortytwo IAM Core Connector API.

.DESCRIPTION
    Posts a timestamped log message to the connector's log endpoint in the Fortytwo IAM platform.
    Useful for recording sync progress or errors that should be visible in the platform.
    When Connect-Connector was given a -SyncJobId, every entry carries it, so the platform can
    correlate the log with the sync job. Failures to send are surfaced as warnings rather than
    terminating errors.

.PARAMETER Text
    The log message to send.

.PARAMETER Type
    The severity of the log entry. Must be one of: Info (default), Warning, Error.

.EXAMPLE
    Send-ConnectorLog -Text "Sync started"

.EXAMPLE
    Send-ConnectorLog -Text "Failed to process user" -Type Error
#>

function Send-ConnectorLog {
    [CmdletBinding()]

    Param(
        [Parameter(Mandatory = $true, Position = 0)]
        [string] $Text,
        
        [Parameter(Mandatory = $false, Position = 1)]
        [ValidateSet("Info", "Warning", "Error")]
        [string] $Type = "Info"
    )

    Process {
        try {
            $Body = @{
                Message   = $Text
                Type      = $Type
                Timestamp = (Get-Date).ToUniversalTime().ToString("o")
            }
            if ($Script:SyncJobId) {
                $Body.SyncJobId = $Script:SyncJobId
            }
            Invoke-RestMethod `
                -Uri "$($Script:APIRoot)log" `
                -Method Post `
                -Verbose:$false `
                -ContentType "application/json" `
                -Body ($Body | ConvertTo-Json -Depth 30) `
                -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile) | out-null
            Write-Debug "Sent log entry of type '$Type' with message: $Text"
        }
        catch {
            Write-Warning "Unable to send log entry of type '$Type' with message: $Text"
        }
    }
}