IIS web server

How to Delete IIS Log Files on Windows Server 2012

IIS (Internet Information Services) Web Server on Windows Server generates a sufficiently large amount of log files during its work. The main problem is that by default IIS log files located on the system drive, which usually has a small size. Insufficient space on the system drive may eventually cause to server crash. Continuous extension of the system drive (even on a virtual machine) due to the large size of the IIS log files also is not the best solution.

Delete IIS Log Files on Windows Server 2012

In this article we will show you how to handle the IIS log files and automate the process of their deleting on Windows Server 2012.

By default, IIS logs stored in the directory:

  • Windows Server 2003: %windir%\system32\LogFiles\
  • Windows Server 2012/2008: %SystemDrive%\inetpub\logs\LogFiles\

Administrator can change the path to the logs using the Internet Information Services (IIS) Manager snap-in by specifying the required directory in the Logging section of site settings.

iis logging configure

In our case, on Exchange Server 2013 with almost 1,000, IIS generate about 200 MB file per day. Thus, for the year it accumulated about 70 GB of logs!

In case of exhaustion space on the servers system drive, system administrators are beginning to look for what takes so much space, and safely passed inetpub folder, because, at first glance, it has small size. This is because by default Administrator does not have permissions on the subfolders of inetpub, so File Explorer does not show the real size of folder.

READ ALSO  How to Recreate OWA and ECP Virtual Directories on Exchange Server 2016

iis log properties

Try to open each subfolder in the directory %SystemDrive%\inetpub\logs\LogFiles, agreeing with the appointment of the necessary permission and eventually see that the real volume of folders is not so small.

iis log permissions

As a rule, you can safely remove all the log files older than 3-7 days. You can do this manually (not the best choice), or automatically using PowerShell script that will be cleaning log files on schedule.

PowerShell script that will remove all files older than 7 days in the directory C:\inetpub\logs with the *.log extension might be look like this:

gci ‘C:\inetpub\logs -Include ‘*.log’ -Recurse | ? LastWriteTime -LT (Get-Date).AddDays(-7) | Remove-Item

To run this script automatically, create a new job using Task Scheduler:

  • Run Task Scheduler
  • In the Action pane select Create Basic Task
  • Specify task Name: CleanUpIISLogs
  • Trigger task to start weekly on Sunday
  • Action: Start a program
  • Program: exe
  • Arguments: -NoProfile -command “gci ‘C:\inetpub\logs’ -Include ‘*.log’ -Recurse | ? LastWriteTime -LT (Get-Date).AddDays(-7) | Remove-Item”
    start programm powershell
  • Open Properties of the created task
    task scheduler library
  • Now change the user under which the task runs to NT AUTHORITY\System and check the option Run with highest privileges
    iis log cleanup
  • To test the task, right click on it and select Run
    cleanup IIS Log Files
  • Make sure that the log files older than 7 days is removed

Bonus tip. Enabling NTFS compression for the whole folder is another great way to quickly reduce the size of the directory with IIS log file. Since log files contain simple text records, their size is reduced significantly when compressed (approximately in 4x times). To enable compression, select Logs folder properties and click on the Advanced button. Check the box Compress contents to save disk space and press OK twice.

READ ALSO  Windows 10 Guide on Using Windows Defender antivirus antimalware spyware tool

iis logs advanced

You may also like:

How to Truncate SQL Server 2012 Transaction Logs Transaction logs in SQL Server 2012 tend to grow over time, which can sometimes fill all your available disk space. To avoid this, SQL Server has a lo...
How to Setup an FTP Server in Windows 10 Today we will show you how to setup and access an FTP server in Windows 10. At first let’s create an FTP folder. This folder will be accessed by our F...
How to set CPU Usage limit for Application Pool on... The important function of web server is the ability to limit the CPU usage for a specific site, otherwise one website can use all the CPU resources, t...
Building IIS Web Farm with Load Balancing using Ng... This article describes how to create a web farm with load balancing on Internet Information Services (IIS) 8.0 and higher. Load balancing between Web ...
How to configure, view and change IIS Log location... Web server IIS 10.0 (Internet Information Services) on Windows Server 2016, as in previous versions, supports storing of HTTP requests and error logs ...