Write Log - PPOSHGROUP/PPoShTools GitHub Wiki
Writes a nicely formatted Message to stdout/file/event log.
Write-Log [-Error] [-Warn] [-Info] [-_debug] [-Emphasize] [-NoHeader]
[-Message] <String[]> [[-Indent] <Int32>] [-PassThru] [<CommonParameters>]
It uses optional $LogConfiguration object which describes logging configuration (see LogConfiguration.ps1). It can be set using Set-LogConfiguration function.
If specified, an error will be logged.
- DefaultValue: False
- PipelineInput: false
- Required: false
If specified, a warning will be logged.
- DefaultValue: False
- PipelineInput: false
- Required: false
If specified, an info message will be logged (default).
- DefaultValue: False
- PipelineInput: false
- Required: false
If specified, a debug message will be logged.
- DefaultValue: False
- PipelineInput: false
- Required: false
If set, the message at console will be emphasized using colors.
- DefaultValue: False
- PipelineInput: false
- Required: false
If specified, header information will not be logged (e.g. '[ERROR]: (function_name)').
- DefaultValue: False
- PipelineInput: false
- Required: false
Message to output.
- PipelineInput: true (ByValue)
- Required: true
Additional indent.
- DefaultValue: 0
- PipelineInput: false
- Required: false
If enabled, all log output will be available as return value (will use Write-Output instead of Write-Host).
- DefaultValue: False
- PipelineInput: false
- Required: false
Write-Log -Info "Generating file test.txt."
[I] 2017-05-19 11:14:28 [hostName/userName]: (scriptName/commandName/1) Generating file test.txt.
Set-LogConfiguration -LogLevel Warn
Write-Log -Info "Generating file test.txt." Write-Log -Error "Failed to generate file test.txt." [E] 2017-05-19 11:14:28 [hostName/userName]: (scriptName/commandName/1) Failed to generate file test.txt.
Set-LogConfiguration -LogFile 'log.txt'
Write-Log -Info "Generating file test.txt." Logs message to stdout and log.txt file.
Set-LogConfiguration -LogEventLogSource 'MyApplication' -LogEventLogThreshold Warn
Write-Log -Warn "Failed to generate file test.txt."