IIS Logs cleanup

Nandan NK 50 Reputation points
2024-05-30T09:07:39.2833333+00:00

We have IIS in exchange 2019 server and logs are stored in the C:\inetpub\logs\LogFiles\W3SV2, but we are cleaning up the logs every 9 month as it is utilizing the more space, while talking to my senior I came to know that IIS itself had settings for rotating logs and delete older once.

Can anyone conform is that setting still exist, if not what is the effective way to do that without and third-party tool.

Thanks

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,229 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,670 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Zunhui Han 2,395 Reputation points Microsoft Vendor
    2024-05-30T10:15:58.8566667+00:00

    Hello Nandan NK,

    Thank you for posting in Q&A forum.

    Depending on your needs, you can refer to the following links first.

    https://learn.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/managing-iis-log-file-storage

    I hope the information above is helpful.

    Best regards

    Zunhui

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.


  2. MotoX80 34,431 Reputation points
    2024-05-30T11:54:43.22+00:00

    IIS has a setting to limit the number of failed request tracing log files, but not the primary HTTP request log files.

    A simple solution as that link indicates is to use the task scheduler to run a script to purge the old files. The sample script is written in VB script which Microsoft has announced is effectively end-of-life, so a better choice is Powershell.

    A purge script is trivial.

    Start-Transcript -Path "C:\Scripts\Logs\IIS-Log-File-Purge.log"   # use your file/folder name
    $DaysToKeep = 200                                                 # how many days to keep  
    $path = "C:\inetpub\logs"                                         # path to your log files 
    $AllFiles = Get-ChildItem -Path $path -Recurse -Filter *.log
    "Total log file count is {0}" -f $AllFiles.count  
    $PurgeFiles = $AllFiles | Where-Object -Property lastwritetime -LT (get-date).AddDays(($DaysToKeep * -1))
    "Selected for delete is {0}" -f $PurgeFiles.count  
    $PurgeFiles
    $PurgeFiles | Remove-Item -WhatIf           # remove -whatif after testing to actually delete the files 
    Stop-Transcript
    

    Save that as a .ps1 file somewhere and define a task to run it. You probably only need to run it once a week. Use the SYSTEM account as the account that the task executes as.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.