< Back

Write-Log

Sat Jan 18, 2020 9:51 am

NAME Write-Log



SYNOPSIS

Emits a log record





SYNTAX

Write-Log [-Message] <String> [[-Arguments] <Array>] [[-Body] <Object>] [[-ExceptionInfo] <ErrorRecord>]

[<CommonParameters>]





DESCRIPTION

This function write a log record to configured targets with the matching level





PARAMETERS

-Message <String>

The text message to write



Required? true

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Arguments <Array>

An array of objects used to format <Message>



Required? false

Position? 4

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Body <Object>

An object that can contain additional log metadata (used in target like ElasticSearch)



Required? false

Position? 5

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ExceptionInfo <ErrorRecord>

An optional ErrorRecord



Required? false

Position? 6

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Write-Log 'Hello, World!'













-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Write-Log -Level ERROR -Message 'Hello, World!'













-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Write-Log -Level ERROR -Message 'Hello, {0}!' -Arguments 'World'













-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Write-Log -Level ERROR -Message 'Hello, {0}!' -Arguments 'World' -Body @{Server='srv01.contoso.com'}















RELATED LINKS

https://logging.readthedocs.io/en/lates ... ite-Log.md

https://logging.readthedocs.io/en/lates ... ngLevel.md

https://github.com/EsOsO/Logging/blob/m ... te-Log.ps1