From 9a4254378c0d41dfdb3af1dc4062e256c6769b0c Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Mon, 4 Mar 2024 14:53:18 +0000 Subject: [PATCH] Fix: Fix `copytruncate` to work when another process has an read lock on the log file Fixes #52 --- src/Log-Rotate/classes/New-LogObject.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Log-Rotate/classes/New-LogObject.ps1 b/src/Log-Rotate/classes/New-LogObject.ps1 index 204d868..f31ac1e 100644 --- a/src/Log-Rotate/classes/New-LogObject.ps1 +++ b/src/Log-Rotate/classes/New-LogObject.ps1 @@ -29,7 +29,8 @@ function New-LogObject { if ($copytruncate) { Write-Verbose "Truncating $my_fullname" if (!$WhatIf) { - Clear-Content $my_fullname + # Truncate the file + [IO.File]::WriteAllText($my_fullname, '') } }else { Write-Verbose "Not truncating $my_fullname"