Aleksandr
Aleksandr

Reputation: 41

nssm log rotation. How to limit files number

I use NSSM to install and start my Windows services. Also I am trying to rotate log files by size and limit their number. Rotation by size was implemented, but I can not limit number of files.

Issue is that for a few time in log directory will be too many log files and this directory could become too large.

Currently I use this code to configure logs

nssm install SERVICE_NAME %FC_WEB_BAT%
nssm set SERVICE_NAME AppStdout "%OUTDIR%\logs\SERVICE_NAME\service.log"
nssm set SERVICE_NAME AppStderr "%OUTDIR%\logs\SERVICE_NAME\service-error.log"
nssm set SERVICE_NAME AppStdoutCreationDisposition 4
nssm set SERVICE_NAME AppStderrCreationDisposition 4
nssm set SERVICE_NAME AppRotateFiles 1
nssm set SERVICE_NAME AppRotateOnline 1
nssm set SERVICE_NAME AppRotateSeconds 0
nssm set SERVICE_NAME AppRotateBytes 100
nssm start SERVICE_NAME 

Is there way to say NSSM that I want to store only the N newest files?

Upvotes: 4

Views: 920

Answers (1)

Eboubaker
Eboubaker

Reputation: 800

The documentation does not provide any details on how to do that, but I have an idea, Just create another service that will check the number of the old log files and delete them if they exceed some maximum number based on the documentation on file rotation: https://nssm.cc/usage#rotation

If you are running a self coded program you can insert in it's code somewhere to check if a log file with a timestamp exist and delete it since that log file is old.

Upvotes: 0

Related Questions