Why Clear Exchange Log Files?
Exchange transaction logs are constantly generated as users send and receive messages or use their mailboxes.
According to the Radicati Group (a market research firm), a user sends and receives over 190 email messages per day on average. With such or similar usage, the transaction logs can grow rapidly or high rate, filling up the entire storage volume and leaving no space for new transaction logs or databases.
When this situation arises, Exchange Server may fail to generate newer logs or commit the changes to the database, leading to database inconsistency (integrity issues), corruption, and Dirty Shutdown error.
Thus, it’s important to keep an eye on the disk storage where transaction logs are stored and clear them off frequently (based on the usage) from your server storage. This will help you conserve the storage, make space for new logs and allow Exchange to commit changes to the database, thereby keeping the database consistent and preventing the risk of database corruption or data loss.
Exchange Server Logs Location
Besides transaction logs, Exchange Server also generates IIS logs, daily performance logs, transport logs, and several other logs.
The IIS logs can be found at C:\Inetpub\logs\Logfiles location. The logs are segregated in two folders at this location - W3SVC1 and W3SVC2.
You can find the daily performance logs or performance logs waiting to be processed in your Exchange server installation path.
The default location is C:\Program Files\Microsoft\Exchange Server\v15\Logging\Diagnostics.
However, the transaction logs can grow in large numbers and clog the hard drive. These logs are stored at C:\Program Files\Microsoft\Exchange Server\v15\Logging location.
Methods to Delete or Clear Exchange Log Files
Below we have shared a few recommended and non-recommend methods that you can follow to clear Exchange transaction logs from your server and free up the storage space for newer logs and database. You may choose any based on your level of expertise.
Backup and Clear Exchange Logs (Not Recommended)
This is the simplest and easiest way to clear Exchange log files from the server. In this method, you compress or archive the logs you want to delete in a .zip file, move them to a backup drive location and then delete the backed-up logs from the default location.
However, you must stop the Microsoft Exchange Information Store service before creating a log backup and deleting the logs. Otherwise, you may fail to clear the Exchange log files and encounter permission errors.
Use Command Prompt (Not Recommended)
You can also use the Command Prompt to clear Exchange log files from the server storage. It can delete all logs in a few commands, including logs in folders and subfolders. The Command is as follows:
cd /pathtologfolder /pathtologfolder
For instance,
cd C:\Program Files\Microsoft\ Exchange Server\V15\Logging
del *.log /s
To delete all the logs recursively from any folder and subfolder, use the following Command in the Command Prompt window.
$files = Get-ChildItem -Recurse -Include *.log | Select-Object -expandproperty Name
foreach ($file in $files) {Move-Item $file $archivelocation}
This will remove log files from the current folder to the archive location.
Enable Circular Logging (Recommended in Specific Scenarios)
Circular logging automatically clears off the Exchange log files and conserver the storage space in Microsoft Exchange. It prevents the logs from expanding or growing rapidly.
When you enable Circular Logging, the log size can grow to 1MB. As the log reaches the limit, it’s overwritten automatically to prevent the log database from growing larger. It is disabled by default; however, you can enable it in Exchange 2010 or later.
The only downside of Circular Logging is that if the database becomes inconsistent or corrupt, it cannot be recovered completely as the logs are deleted.
You should only enable this to clear Exchange logs when the hard disk is reaching its limit or nearly full.
Create VSS Backups (Recommended)
The safest way to clear Exchange log files automatically is to create Volume Shadow Service-based backups using the Windows Server Backup in Exchange Server. You may also use a third-party Exchange-aware backup service or software to create backups and purge the transaction logs.
When you take a backup, the transaction logs are automatically committed to the mailbox database and purged.
Use DiskShadow (Not Recommended)
If your log files are not purged after the backup, it indicates an issue with your backup software. If your Exchange server backup software is not working properly or not Exchange-aware, the logs will never purge. In such cases, you can safely purge the logs using the DiskShadow method mentioned below to solve the space problem.
This makes the mailbox databases think there is a backup running and, thus, initiates the process of committing pending logs with the database. Once that happens, you are safe to delete or clear the Exchange log files without the risk of damaging the database. The steps are as follows:
- Open Command Prompt as admin and type the following commands.
Diskshadow
Add Volume C:
Begin backup
Create
Make sure to change the drive letter where your Exchange server database is located in the ‘Add Volume’ command line.
- This will take some time to finish, depending on the size of the databases and the drive where the databases are located.
Once ready, type the end backup command to finish off and purge the Exchange logs.
Conclusion
Following the methods discussed in this article, you can manually purge logs and clear any logs that might be taking your Exchange server space. For businesses, it is always suggested to have a monitoring tool to keep an eye on the storage and act before a disaster strikes. The above methods can help you clear the logs and ensure enough storage for newer ones.
However, if the database is damaged or corrupt due to any reason, such as a server crash, abrupt shutdown, etc., you won’t be able to recover the database completely without the log files.
Thus, it is highly suggested that you take a real backup using Windows Server Backup (WSB) to automatically clear the Exchange logs, as WSB is application-aware and fully compatible with the Exchange server. But if the database gets damaged or corrupt, you can use a third-party application such as Stellar Repair for Exchange to repair the EDB files and export the recovered mailboxes to PST or directly to a new Exchange server database and Office 365s. The software can help minimize the downtime while recovering and restoring all your mailboxes.