Data Recovery Blog

Tips to Clear Exchange Log Files

Read time 6 min

Exchange log files are vital components of the server but can be a trouble when their size increases enormously. Read this blog to understand issues with the log file size and how to get rid of them

Exchange Log Files

Exchange Server holds files like database file, checkpoint file, and log file. Here, we will discuss the Exchange log files that record information about every transaction performed on the server. It can be played/committed to the Exchange Server database and used to restore or recover from Exchange failures. After committing the data to the database from log files, modifications can be rolled back also. It is to be mentioned with each fresh backup of the Exchange Server, log files get removed, and new log files begin to create.
The main Exchange transaction logs are Diagnostic logs or Health Manager, IIS logs, ETL Files, and HTTP Proxy logs. With heavy traffic of information or transactions on the Exchange Server, these log files take a good amount of storage space on the server or the Exchange system, which is not ideal. Let us discuss the issues caused by Exchange log files in the next section.

Exchange Log File Issues

As mentioned earlier, due to heavy traffic on the Exchange, transaction log files are created and piles up, which takes enough space on the server. For Exchange 2010 and above versions, Diagnostic Logs or Health Manager, which stores Exchange health information, take storage space rapidly; in some days, if the Exchange Server storage capacity is already low, ETL files under Diagnostics are generated hour by hour, taking up 50MB space at a time with default entry of 100 files; similarly IIS log files take up more than 200MB space and HTTP proxy files can take 10MB of storage space which, definitely needs to be managed. So one may need to clear almost a GB of storage space on the server.
Some harmful effects of the piled-up Exchange Server log files are poor performance, unmounting of Exchange database, inaccessibility of server and data, corruption in Exchange database, and more.

Different ways to clean up Exchange Log Files

The best way to deal with the issue of log files taking over Exchange Server storage is to clean up these log files. We propose multiple ways to do that further in this blog.

Delete it manually

  1. Deleting Diagnostic Logs:
    • On the Exchange system, run services.msc from the Windows run box.
    • Search for the service and double-click on it.
    • Modify the startup as disabled and stop this service.
    • Perform similar steps for the Microsoft Exchange Diagnostics service.
    • Next, open the Task Scheduler on the Exchange system and navigate to Microsoft>Windows>PLA.
    • On the right panel, stop the two running tasks and disable them.
    • Now, go to C:\Program Files\Microsoft\Exchange Server\V15\Logging\Diagnostic and delete all logs available in DailyPerformanceLogs and PerformanceLogsToBeProcessed folders.
  2. Delete ETL files:
    • Navigate to the location –
      C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces

      Select and delete all the available log files within that folder.

    • Next, move to this location –
      C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs

      Select and delete all the log files within the folder permanently.

  3. Delete IIS files:
    Move to the following path locations and delete log files within them.

    C:\inetpub\logs\LogFiles
    C:\Program Files\Microsoft\Exchange Server\V15\Logging\RpcHttp
  4. Delete HTTP Proxy Logs:
    Find out the folder in this location and deleted the available log files in it.

    C:\Program Files\Microsoft\Exchange Server\V15\Logging\HttpProxy

With VSS Backup Script

It is another way to get rid of Exchange log files. As mentioned earlier, with a full backup of the Exchange database, log files get truncated automatically. The administrators can try running the VSS Backup trick, which uses the Shadow copies functionality to create a snapshot for the drive during the installation of the Exchange Server. This action will truncate the log files, and the commands in the sequence which the administrator needs to run in the Command Prompt window are as follows.

PS C:\> diskshadow
DISKSHADOW> add volume c:
DISKSHADOW> begin backup
DISKSHADOW> create
DISKSHADOW> end backup
DISKSHADOW> exit

Enable Circular Logging

Exchange administrators can also utilize the Circular Logging function and enable it to turn off transaction logs and delete the old logs. It literally means deleting Exchange log files on a rotational or circular basis when the disk space reaches the limit. Thus, it helps in saving the hard disk space actually. Learn enabling circular logging in Exchange 2010.

Use CleanupLogs.ps1 script

To clear exchange logs for versions like Exchange 2013 and above versions, CleanupLogs.ps1 script can be used in the Exchange Management Shell as follows.
Copy this script given below to a .txt file and save it as CleanupLogs.ps1 file name.


# Set execution policy if not set
$ExecutionPolicy = Get-ExecutionPolicy
if ($ExecutionPolicy -ne “RemoteSigned”) {
Set-ExecutionPolicy RemoteSigned -Force
}

# Cleanup logs older than the set of days in numbers
$days = 2

# Path of the logs that you like to cleanup
$IISLogPath = “C:\inetpub\logs\LogFiles\”
$ExchangeLoggingPath = “C:\Program Files\Microsoft\Exchange Server\V15\Logging\”
$ETLLoggingPath = “C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\”
$ETLLoggingPath2 = “C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs\”

# Clean the logs
Function CleanLogfiles($TargetFolder) {
Write-Host -Debug -ForegroundColor Yellow -BackgroundColor Cyan $TargetFolder


if (Test-Path $TargetFolder) {
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = Get-ChildItem $TargetFolder -Recurse | Where-Object { $_.Name -like “*.log” -or $_.Name -like “*.blg” -or $_.Name -like “*.etl” } | Where-Object { $_.lastWriteTime -le “$lastwrite” } | Select-Object FullName
foreach ($File in $Files) {
$FullFileName = $File.FullName
Write-Host “Deleting file $FullFileName” -ForegroundColor “yellow”;
Remove-Item $FullFileName -ErrorAction SilentlyContinue | out-null
}
}
Else {
Write-Host “The folder $TargetFolder doesn’t exist! Check the folder path!” -ForegroundColor “red”
}
}
CleanLogfiles($IISLogPath)
CleanLogfiles($ExchangeLoggingPath)
CleanLogfiles($ETLLoggingPath)
CleanLogfiles($ETLLoggingPath2)

In the above script, you can modify the number of days ($days =) as per your choice. Save this script file at C:\scripts\ path location on the Exchange system and then provide account permissions to these folders –


C:\inetpub\logs\LogFiles\
C:\Program Files\Microsoft\Exchange Server\V15\Logging\
C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\
C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs\

Now, have an account on the available disk space on the server, right-click on the script file, and select run with the PowerShell option. Once the script has run successfully, check the disk space again for reduction this time.

Through Windows Server backup

Windows Server Backup is an inbuilt utility provided by Microsoft that allows Exchange server database backup and restore with an Exchange plug-in. It is used for creating VSS-based Exchange data backups and thus truncate log files. Know how to backup/restore Exchange 2016 using Windows Server backup.

So, now we know how to deal with log files eating up the Exchange server system disk space. But if the damage is already done, i.e., the Exchange database is inaccessible now due to corruption, we got a permanent solution for you in the form of a professional Exchange recovery tool. Kernel for Exchange Server can recover corrupt, damaged Exchange database content quickly and export it to the desired destination or file format. Go to the official website link to get every detail about the tool.

Conclusion

Exchange Server log files can cause different types of issues when they pile up on the server. This piling up can be controlled in different ways. But if the entire Exchange database is corrupt, you may need these log files to recover the lost data. But if you use a professional Exchange recovery tool, you can recover the data without log files.