diff --git a/lib/appenders/file.js b/lib/appenders/file.js index 6ea01ca..c6be910 100644 --- a/lib/appenders/file.js +++ b/lib/appenders/file.js @@ -54,6 +54,14 @@ function fileAppender (file, layout, logSize, numBackups) { function increaseFileIndex (fileToRename) { var idx = index(fileToRename); if (idx < numBackups) { + //on windows, you can get a EEXIST error if you rename a file to an existing file + //so, we'll try to delete the file we're renaming to first + try { + fs.unlinkSync(file + '.' + (idx+1)); + } catch (e) { + //couldn't delete, but that could be because it doesn't exist + //try renaming anyway + } fs.renameSync(path.join(path.dirname(file), fileToRename), file + '.' + (idx + 1)); } }