-
Notifications
You must be signed in to change notification settings - Fork 22
Write InfoLog
Writes Information log message
Write-InformationLog
[-MessageTemplate] <string>
[-Logger <ILogger>]
[-Exception <Exception>]
[-PropertyValues <Object[]>]
[-PassThru]
[<CommonParameters>]Write-InformationLog
[[-MessageTemplate] <string>]
-ErrorRecord <ErrorRecord>
[-Logger <ILogger>]
[-Exception <Exception>]
[-PropertyValues <Object[]>]
[-PassThru]
[<CommonParameters>]Write a log event with the Information level. Note that you can use Write-InfoLog as shortcut.
Write-InformationLog 'My Log Message'Or use pipeline input
'My Log Message' | Write-InformationLogWrite-InformationLog 'My {Number} Log Message.' -PropertyValues 'First'
# Alternatively
Write-InformationLog -MessageTemplate 'My {Number} Log Message.' -PropertyValues 'First'try{
throw 'error'
}
catch{
Write-InformationLog -ErrorRecord $_
}Or specify your own message
try{
throw 'error'
}
catch{
Write-InfoLog 'Error occurred while doing some business! {SomeNumber}' -ErrorRecord $_ -PropertyValues 123
}try{
throw 'error'
}
catch{
Write-InformationLog 'Error occurred while doing some business!' -Exception $_.Exception
}If for whatever reason you want to output a log message as string, you can use -PassThru parameter. Keep in mind that message will still be logged using all sinks.
$message = Write-InformationLog 'Some {What} that will be passed thru' -PropertyValues 'message' -PassThru
$message # Contains string: "Some message that will be passed thru"You can alter ouputted message using Set-DefaultMessageFormatter cmdlet.
Set-DefaultMessageFormatter -Template '[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}'
$message = Write-InformationLog 'Some {What} that will be passed thru' -PropertyValues 'message' -PassThru
$message # Contains string: "[10:26:53 INF] Some message that will be passed thru"Message template describing the event.
| Type: | string |
| Position: | 0 |
| Default value: | |
| Accept pipeline input: | True (ByValue) |
| Accept wildcard characters: | False |
Instance of Serilog.Logger. By default static property [Serilog.Log]::Logger is used.
Use $logger = Start-Logger -PassThru to get instance of logger.
| Type: | Serilog.ILogger |
| Position: | Named |
| Default value: | [Serilog.Log]::Logger |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Exception related to the event.
| Type: | System.Exception |
| Position: | Named |
| Default value: | $null |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
ErrorRecord related to the event.
| Type: | System.Management.Automation.ErrorRecord |
| Position: | Named |
| Aliases: | ER |
| Default value: | $null |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Objects positionally formatted into the message template.
| Type: | object[] |
| Position: | Named |
| Default value: | $null |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
If set outputs MessageTemplate populated with PropertyValues into pipeline.
| Type: | SwitchParameter |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Built upon Serilog. If you are missing some info, try to look at serilog wiki.