Private/Write-CheckIDPasswordAgentEventLog.ps1

function Write-CheckIDPasswordAgentEventLog {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true)]
        [string]$Message,

        [Parameter(Mandatory = $true)]
        [int]$EventId,

        [Parameter(Mandatory = $true)]
        [System.Diagnostics.EventLogEntryType]$EntryType
    )

    Process {
        # First argument of the static WriteEntry overload is the event *source*, not the log name.
        try {
            [System.Diagnostics.EventLog]::WriteEntry($Script:EventLogSource, $Message, $EntryType, $EventId)
        }
        catch {
            if (!$Script:EventLogSourceWarningShown) {
                $Script:EventLogSourceWarningShown = $true
                Write-Warning "Failed to write to event log source '$($Script:EventLogSource)': $_. Run Install-CheckIDPasswordAgentLogging as administrator once to create the source."
            }
            Write-Verbose "Failed to write CheckIDPasswordAgent event log entry: $_"
        }
    }
}