如何设置IIS以旋转日志?

我已经使用了Apache多年,我认为它为我处理日志旋转。 我一直在挖掘IISconfiguration和谷歌search,但我找不到IIS的选项来打开日志的旋转。

什么是configurationIIS删除超过一定的阈值日志的首选方法? 有没有什么产品为你做这个? Windows商店做什么?

configuration:IIS 6.0 / Windows Server 2003 32位

没有内置的机制来处理日志的旋转或归档。 可能有第三方产品来处理这件事,或者你可以编写脚本并configuration一个计划任务。 我只有IIS服务器,所以我只是在Outlook中设置一个重复的任务来提醒我每月删除超过30天的IIS日志文件。

检查: http : //www.808.dk/?code-iis-log-housekeeping

一堆脚本是可用的,你可以添加在计划任务= logrotation 🙂

看看IIS日志工具( http://www.iislogs.com/ )。 有几种不同的方式来安装这个,并做一个非常有效的工作来pipe理IIS和其他日志文件(压缩文件为.zip格式,将它们移动到不同的位置,删除超过特定date的文件等)。

设置计划任务以使用robocopy将文件复制到名为“old”的子目录。 它有一个开关,/ minage:x,你可以设置为30,60,或者任何你感觉到的。 然后删除该目录中的所有内容。 我在几十台服务器上这样做,它似乎有伎俩。

IIS 7引入了一个configuration来定期删除日志文件。 有关更多信息,请查看以下链接中的period

http://www.iis.net/configreference/system.applicationhost/log/centralbinarylogfile

http://www.iis.net/configreference/system.applicationhost/log/centralw3clogfile

其他答案是好的,并提供一个更强大的解决这个问题。 如果您只需要快速修复,则可以将CCleaner设置为每次login时或按计划自动清理日志文件夹。

请记住,这将删除所有日志,而不仅仅是老化文件。

我遵循这些说明,但补充说,即使在用户注销时,我也希望它运行,就像服务器上的正常情况一样。

我最近在Powershell.org论坛上提出了同样的问题 。 然后结束了发布一个脚本资源为希望的状态configuration,我将用于解决我的日志清除例程的需要。 也许这些代码中的一些对别人有用。

 # Requires an E: drive. configuration LogDirectory { param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string[]]$Node ) node $Node { Script LogDirectoryScript { GetScript = { $result = (Test-Path 'E:\log') -and (schtasks.exe /query /TN Purge_Log_Folder | Select-String Purge_Log_Folder -Quiet) return @{ GetScript = $GetScript SetScript = $SetScript TestScript = $TestScript Result = $result } } SetScript = { Write-Verbose 'Creating log directory.' if ( -not (Test-Path 'E:\log')) { New-Item -ItemType Directory -Path 'E:\log' } Write-Verbose 'Changing permissions to log directory such that any user can write, but only an administrator can read or modify.' $acl = (Get-Item 'E:\log').GetAccessControl('Access') $acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule('Users','Write', 'Allow'))) Set-Acl -Path 'E:\log' -AclObject $acl | Out-Host Write-Verbose 'Scheduling purge task.' $script = 'Get-ChildItem E:\log\* -Include ex*.log -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Remove-Item' Set-Content -Path C:\Windows\Purge_Log_Folder.ps1 -Value $script $task = 'Powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -File C:\Windows\Purge_Log_Folder.ps1' SCHTASKS /CREATE /TN Purge_Log_Folder /TR $task /SC DAILY /ST 23:59 /RU SYSTEM /F | Out-Host Write-Verbose 'Configuring IIS' # Default Log File Settings for Web Sites <logFile> # http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults/logfile Import-Module WebAdministration Set-WebConfigurationProperty '/system.applicationHost/sites/siteDefaults' -name logFile -value @{ directory = 'E:\log' localTimeRollover ='true' period = 'Hourly' } } TestScript = { (Test-Path 'E:\log') -and (schtasks.exe /query /TN Purge_Log_Folder | Select-String Purge_Log_Folder -Quiet) } } } } LogDirectory