Right way of logging

Happy to see you figured out your issue.

You might be interested in this too: How to Log built-in PowerShell commands (non-PSADT commands)