How do I combine 2 Error outputs into one

Below enters 2 different lines into my Log upon Error:

## The location/filename where the Logs will be stored
$varfullpath = "C:\Users\Simon.Evans\Documents\ReferenceData__logfile.txt"

## The location/filename of the Source to copy from 
$sourceDirectory = "C:\Users\Simon.Evans\Documents\Source Data\LNAT\Code_Maping.txt"

## The location/filename of the Destination to copy to 
$destinationDirectory = "I:\Dev\BI\Projects\Powershell\Test Area\Source Data\LNAT\Code_Mapping.txt"

## Attempts to copy a file fron Source to Destination and record the event, if the Copy-item fails the script is halted and the error messages are captured
## Possibly only 1 error is needed and or applicable, so remove as necessary.
try{
Copy-item -Force -Verbose $sourceDirectory -Destination $destinationDirectory -ErrorAction Stop 
Write-log -Message "Copy from $sourceDirectory to $destinationDirectory suceeded" -path $varfullpath 
}
catch{
$Error[0] | Write-Log -path $varfullpath 
Write-log -Message "Copy from $sourceDirectory to $destinationDirectory Failed" -Level Error -path $varfullpath 
}

Essentially I couldn’t decide which error to use the system error or the custom error as both provide different information, so wondered if they could be concatinated into just one entry rather than two lines.

 

 

 

https://stackoverflow.com/questions/56767555/how-do-i-combine-2-error-outputs-into-one