In our AWS environment, Log4net is used for logging exceptions from Auto scaled Beanstalk IIS env behind an elastic Load balancer. There are also worker instances and CodeDeploy service used.
Both Worker instances and Beanstalk instances write logs using log4net to udp stream as well as log files. Rolling by date and size is possible. rotating/deleting logs older than n days is not possible in log4net. This is pending for years: https://issues.apache.org/jira/browse/LOG4NET-367
Due to Auto scaling, using batch file to delete log file solder than n days is not possible for me. What option Do I have to delete the older logs from the hosts?
UPDATE# 1
How about this??
commands:
0_mkdir:
command: mkdir C:\\scripts\\
1_create_script:
file: C:\\scripts\\delAppLogs.bat
content: |
forfiles /p "C:\AppLogs" /s /m *.* /D -30 /C "cmd /c del @path"
2_runSched_delAppLogs:
command: SchTasks /Create /SC DAILY /TN "Delete Logs" /TR "c:\scripts\delAppLogs.bat" /ST 23:55 /RU SYSTEM
Update# 2 use switch /RU on SchTasks for running scripts non interactively.
You need to use ebextensions to customize the server and create a scheduled task that cleans up old logs.
Create a yaml init.config
file inside a folder called .ebextensions
in your web application root. Also add a bat/ps file to do the deletion with your application (or download one from s3) that set the contents of yaml as follows:
commands:
00-log-cleanup:
command: SchTasks /Create /SC DAILY /TN "Delete Logs" /TR "c:\myapp\deletelogs.bat" /ST 23:55
Read more about ebextensions here. Read about scheduled tasks utility here.