Replies: 3 comments 2 replies
-
Hi, I'm not sure if I understand that correctly. Can you please show me example of what you are trying to accomplish? thx Edit Import-module PoShLog
New-Logger |
Add-SinkConsole |
Start-Logger
# Change EA preference variable to SilentlyContinue
$previsousEAP = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
# Trap setup to log unhandled exceptions using PoShLog
trap {
Write-ErrorLog -MessageTemplate $_ -ErrorRecord $_
}
# Your script starts here
# Some code that throws an error
1/$null
# Your script ends here
# Change EA preference variable back to it's previous state
$ErrorActionPreference = $previsousEAP
Close-Logger Previous code would produce similar output:
|
Beta Was this translation helpful? Give feedback.
-
Hi Tomas, New-Logger | $previsousEAP = $ErrorActionPreference trap { Get-ChildItem -Path 'C:\Path_not_exist' -Filter *.txt $ErrorActionPreference = $previsousEAP Close-Logger |
Beta Was this translation helpful? Give feedback.
-
Hi Tomas, Is there another way without $ErrorActionPreference, $WarningPreference etc. to write the console output to a log? I often use foreign scripts and modules and don't want to make any customizations there ... |
Beta Was this translation helpful? Give feedback.
-
it is possible to log the whole console output without Write-*Log so that unhandled exceptions are recorded?
Beta Was this translation helpful? Give feedback.
All reactions