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