I have written a function that writes information to a logfile in JSON format. Each log entry has lots of information that could help the person who reads the logfile. For instance,
“date”: “the date”,
“Message”: “Creating user xyz”,
“CmdledUsed”: “Get-ADUser -Identity xyz”,
“CmdletToReverseChange”: “Remove-ADUser -identity xyz”
So I call “Write-LogFileJson” when I want to log information to the logfile. The reason I am using JSON is because it is easier for someone else to read the information.
The problem I have is that it is incredibly inefficient to read all of the JSON file, to then append the new log entry (obviously).
Is there a more efficient way to do this? I mean to append the JSON file without reading it first before each time the function is called.
I don’t want the script to slow down just because the logfile happened to be really large. I mean I could use runspaces/jobs for that but then I will most likely encounter locked file issues.
Just need help with some ideas of how I can do this a bit more efficient. Maybe I just need to rethink the whole concept.