diff --git a/lib/winston/transports/file.js b/lib/winston/transports/file.js index 9917311e4..04bda7fe2 100644 --- a/lib/winston/transports/file.js +++ b/lib/winston/transports/file.js @@ -553,11 +553,15 @@ File.prototype._getFile = function (inc) { // Check for maxFiles option and delete file if (this.maxFiles && (this._created >= (this.maxFiles - 1))) { remaining = this._created - (this.maxFiles - 1); - if (remaining === 0) { - fs.unlinkSync(path.join(this.dirname, basename + ext)); - } - else { - fs.unlinkSync(path.join(this.dirname, basename + remaining + ext)); + try { + if (remaining === 0) { + fs.unlinkSync(path.join(this.dirname, basename + ext)); + } + else { + fs.unlinkSync(path.join(this.dirname, basename + remaining + ext)); + } + } catch (e) { + // If the file was already removed } }