I am trying to find the best method to format my PowerShell logging. What I am trying to achieve is the following. I want to precede all lines sent to the log file with the following:
[07-30-2020 17:15:44 -0700 INFO] yada yada yada …
So, precede log entries with [month-day-year hours:minutes:seconds timezone INFO] similar to Splunk logging.
I have no problems getting this format, but it seems like a performance hit to calculate the date/time information for each line logged (of which there are many). Is there a better way then running Get-Date for each line logged?
I should also point out this is all run through Start-Transcript.
Have you tried .NET methods? I would imagine that Get-Date is just a wrapper for these. Would have to use ToString() or string format after you have the date.