Description
RotatingStreamWriter.cs lines 354–383 silently catch all exceptions on File.Move() during log rotation without retrying. If the move fails, the current log file continues growing past the rotation size limit.
Scenario
- Antivirus briefly locks the log file during a scan
File.Move() throws IOException
- Exception is silently caught
- Log file continues growing past
_rotationSizeInBytes
- No retry, no warning logged
- Eventually disk fills up
Suggested Fix
Add a short retry loop before giving up:
const int maxRetries = 3;
for (int attempt = 0; attempt < maxRetries; attempt++)
{
try
{
File.Move(_file.FullName, rotatedPath);
EnforceMaxRotations();
return; // success
}
catch (IOException) when (attempt < maxRetries - 1)
{
Thread.Sleep(50 * (attempt + 1));
}
catch
{
break; // non-IO error, give up
}
}
// If all retries fail, log a warning so the operator knows rotation is stuck
Logger.Warn($"Log rotation failed after {maxRetries} attempts: {_file.FullName}");
Description
RotatingStreamWriter.cslines 354–383 silently catch all exceptions onFile.Move()during log rotation without retrying. If the move fails, the current log file continues growing past the rotation size limit.Scenario
File.Move()throwsIOException_rotationSizeInBytesSuggested Fix
Add a short retry loop before giving up: