# https://github.com/EsOsO/Logging
# Install-Module Logging
Import-Module Logging
Set-LoggingDefaultLevel -Level 'WARNING'
Add-LoggingTarget -Name Console
Add-LoggingTarget -Name File -Configuration @{ Path = 'C:\Temp\example_%{+%Y%m%d}.log'; Encoding = 'UTF8' }
$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 Note