-
Notifications
You must be signed in to change notification settings - Fork 45
Home
Massimo Bonvicini edited this page Aug 27, 2019
·
3 revisions
- Add‐LoggingLevel
- Add‐LoggingTarget
- Get‐LoggingAvailableTarget
- Get‐LoggingCallerScope
- Get‐LoggingDefaultFormat
- Get‐LoggingDefaultLevel
- Get‐LoggingTarget
- Get‐LoggingTargetAvailable
- Set‐LoggingCallerScope
- Set‐LoggingCustomTarget
- Set‐LoggingDefaultFormat
- Set‐LoggingDefaultLevel
- Wait‐Logging
- Write‐Log
Set-LoggingDefaultLevel -Level 'WARNING'
Add-LoggingTarget -Name Console
Add-LoggingTarget -Name File -Configuration @{Path = 'C:\Temp\example_%{+%Y%m%d}.log'}
$Level = 'DEBUG', 'INFO', 'WARNING', 'ERROR'
foreach ($i in 1..100) {
Write-Log -Level ($Level | Get-Random) -Message 'Message n. {0}' -Arguments $i
Start-Sleep -Milliseconds (Get-Random -Min 100 -Max 1000)
}
Wait-Logging # See NoteWhen used in unattended scripts (scheduled tasks, spawned process) you need to call Wait-Logging to avoid losing messages. If you run your main script in an interactive shell that stays open at the end of the execution you could avoid using it (keep in mind that if there are messeages in the queue when you close the shell, you'll lose it)