Simple Powershell script that will find all of the files with the .log extension on the specified path that are older than  2 days, it will loop over all of the logs, check if they are locked by application, in case they are not locked, they will be cleaned up.

Feel free to to tune the script to fit your needs in case you want to cleanup logs that are older than specified date or so...

Code below;

PowerShell
Edit|Remove
$ErrorActionPreference = "SilentlyContinue" 
# Find all logs 
$rootpath = "E:\" 
$loglist = Get-ChildItem -Path $rootpath *.log -Recurse| ? {$_.LastWriteTime -lt $date| select -ExpandProperty fullname 
# Function to test if file is locked 
function Test-FileLock { 
  param ( 
    [parameter(Mandatory=$true)][string]$Path 
  ) 
 
  $oFile = New-Object System.IO.FileInfo $Path 
 
  if ((Test-Path -Path $Path-eq $false) { 
    return $false 
  } 
 
  try { 
    $oStream = $oFile.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None) 
 
    if ($oStream) { 
      $oStream.Close() 
    } 
    $false 
  } catch { 
    # file is locked by a process. 
    return $true 
  } 
} 
# Go over loop and test if logs are locked 
foreach ($log in $loglist) { 
    $Test = Test-FileLock -Path $log 
    # Remove log in case it is not locked 
    if ($Test -eq $false) { 
        Remove-Item -Path $log -Confirm:$false -Force 
    } 
}