Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Log {
- [string]$path
- # Constructor
- Log ([string] $path) { $this.path = $path }
- [void] info ([String] $message) {
- Write-Host $message
- $this.writeFile($message)
- }
- hidden [void] writeFile ([String]$message) {
- $message | Add-Content -Path $this.path -EA Stop
- }
- }
- $block = {
- foreach ($y in 1..100) {
- ($using:log).info("Logging from RSJob. Test #$y")
- }
- }
- Try {
- $log = [Log]::New("$PSScriptRoot\test.txt")
- foreach($x in 1..100) {
- $log.info("Logging from Main function. Test #$x")
- }
- Start-RSJob -Name "job1" -ScriptBlock $block
- While ($true) {
- start-sleep 1
- }
- }
- Finally {
- Get-RSJob -Name "job1" | Remove-RSJob -Force
- }
Add Comment
Please, Sign In to add comment