-
-
Notifications
You must be signed in to change notification settings - Fork 46
Description
As the title suggests, when I try to log messages from a parallel process, the messages become jumbled when written to the host.
Sample script:
1..10 | ForEach-Object -Parallel {
1..3 | ForEach-Object -Parallel {
Write-PSFMessage -Level Host '[SomeInfo] This is a test'
} -ThrottleLimit 2
} -ThrottleLimit 3(the parallel nesting here is not required to cause the issue, but it makes the issue much more prevalent)
Sample output:
[[[[15:14:0515:14:05][<ScriptBlock>] [SomeInfo] This is a test
[15:14:05[][<ScriptBlock>] [SomeInfo] This is a test
][<ScriptBlock>15:14:05] [SomeInfo] This is a test
][<ScriptBlock>] [SomeInfo] This is a test
15:14:05][<ScriptBlock>] [SomeInfo] This is a test
[15:14:05][<ScriptBlock>] [SomeInfo] This is a test
[15:14:05][<ScriptBlock>] [SomeInfo] This is a test
15:14:05][<ScriptBlock>] [SomeInfo] This is a test
[15:14:05][<ScriptBlock>] [SomeInfo] This is a test
[[15:14:0715:14:07][][<ScriptBlock><ScriptBlock>] [SomeInfo] This is a test
] [SomeInfo] This is a test
[15:14:07[][<ScriptBlock>] [SomeInfo] This is a test
15:14:07][<ScriptBlock>] [SomeInfo] This is a test
[15:14:07][<ScriptBlock>] [SomeInfo] This is a test
[15:14:07][<ScriptBlock>] [SomeInfo] This is a test
[15:14:07][<ScriptBlock>] [SomeInfo] This is a test
[15:14:07][<ScriptBlock>] [SomeInfo] This is a test
[15:14:07][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[15:14:08][<ScriptBlock>] [SomeInfo] This is a test
[[15:14:09][<ScriptBlock>] [SomeInfo] This is a test
15:14:09][<ScriptBlock>] [SomeInfo] This is a test
[15:14:09][<ScriptBlock>] [SomeInfo] This is a test
Not sure if there's anything I can do here to help prevent the messages from being jumbled up.
I'm currently in the process of migrating to PSFramework for my logging. Prior to using PSFramework, I ran into this same issue when trying to handle logging myself, and the solution I had come up with at the time was to write log messages as output and then place my log writer function in the pipeline to capture the output of ForEach-Object.
Example:
1..10 | ForEach-Object -Parallel {
1..3 | ForEach-Object -Parallel {
Write-Output '[SomeInfo] This is a test'
} -ThrottleLimit 2
} -ThrottleLimit 3 *>&1 | Write-LogThis way it was always logged serially. But it's kind of a dirty solution that I'm hoping PSFramework can resolve.
I realize that there is a console logging provider, but I want to use the message provider so that I can include colors.