简体   繁体   English

IIS 7日志文件自动删除?

[英]IIS 7 Log Files Auto Delete?

Is there any feature in IIS 7 that automatically deletes the logs files older than a specified amt of days? IIS 7中是否有任何功能可以自动删除超过指定amt天数的日志文件?

I am aware that this can be accomplished by writing a script(and run it weekly) or a windows service, but i was wondering if there is any inbuilt feature or something that does that. 我知道这可以通过编写脚本(并每周运行一次)或Windows服务来完成,但我想知道是否有任何内置功能或其他功能。

Also, Currently we turned logging off as it is stacking up a large amount of space. 此外,目前我们在堆积大量空间时关闭了注销。 Will that be a problem? 这会有问题吗?

You can create a task that runs daily using Administrative Tools > Task Scheduler. 您可以使用“管理工具”>“任务计划程序”创建每日运行的任务。

Set your task to run the following command: 将任务设置为运行以下命令:

forfiles /p "C:\inetpub\logs\LogFiles" /s /m *.* /c "cmd /c Del @path" /d -7

This command is for IIS7, and it deletes all the log files that are one week or older. 此命令适用于IIS7,它会删除一周或更早的所有日志文件。

You can adjust the number of days by changing the /d arg value. 您可以通过更改/d arg值来调整天数。

One line batch script: 一行批处理脚本:

forfiles /p C:\inetpub\logs /s /m *.log /d -14 /c "cmd /c del /q @file"

Modify the /d switch to change number of days a log file hangs around before deletion. 修改/ d开关以更改日志文件在删除之前挂起的天数。 The /s switch recurses subdirectories too. / s开关也会递归子目录。

Ref: http://debug.ga/iis-log-purging/ 参考: http//debug.ga/iis-log-purging/

Similar solution but in powershell. 类似的解决方案,但在powershell。

I've set a task to run powershell with the following line as an Argument.. 我已经设置了一个任务来运行powershell,并使用以下行作为参数。

dir D:\IISLogs |where { ((get-date)-$_.LastWriteTime).days -gt 15 }| remove-item -force

It removes all files in the D:\\IISLOgs folder older than 15 days. 它会删除超过15天的D:\\ IISLOgs文件夹中的所有文件。

Another viable Powershell one-liner: 另一个可行的Powershell单线程:

Get-ChildItem -Path c:\inetpub\logs\logfiles\w3svc*\*.log | where {$_.LastWriteTime -lt (get-date).AddDays(-180)} | Remove-Item -force

In case $_.LastWriteTime doesn't work, you can use $PSItem.LastWriteTime instead. 如果$_.LastWriteTime不起作用,您可以使用$PSItem.LastWriteTime

For more info and other suggestions to leverage the IIS LogFiles folder HDD space usage, I also suggest to read this blog post that I wrote on the topic. 有关利用IIS LogFiles文件夹HDD空间使用的更多信息和其他建议,我还建议阅读我在该主题上撰写的这篇博文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM