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  Track messages in Exchange 2013 using Get-MessageTrackingLog

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 Start menu as a calculator, converter and reference

iis logs advanced

You may also like:

How to Truncate SQL 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 Trun...
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 ...
Guide to SQL Server Transaction Log Backup In case you use Microsoft SQL Server you might heard about the Simple and Full database recovery models. Probably you also know that a Simple recovery...
How to Install and Configure IIS Web Server with P... This guide will show you how to deploy your own IIS Web server, and enable it to run PHP on Windows 8 / Windows Server 2012. Thereafter this platform ...
How to Install phpMyAdmin on IIS in Windows 8/Serv... PHPMyAdmin is a web-based open source tool written in PHP designed to help manage MySQL database through the Web browser. Because of this PhpMyAdmin f...