使用power shell启用iis日志记录

时间:2015-12-28 19:58:49

标签: powershell iis

我有带有iis 7的Windows 2008 R2服务器

我创建了一个脚本来启用iis记录到特定网站

我可以更改以下参数:

$logdir = "E:\IISLog"
$logFormat = "W3C"
$logEncoding = "UTF-8"
$period = "Weekly"
$truncateSize = "20971520"
$logExtFileFlags =  "Date,Time,ClientIP,UserName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,TimeTaken,ServerPort,UserAgent,HttpSubStatus,Host,ComputerName"

Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{directory=$logdir}
                Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{format=$logFormat}
                Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{encoding=$logEncoding}
                Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{period=$period}
                Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{truncateSize=$truncateSize}
                Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{logExtFileFlags=$logExtFileFlags}
                Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{enabled="True"}

我也尝试过 $ true 但也没有工作

Set-ItemProperty "IIS:\Sites\$webSiteToEnableLogs" -name logFile -value @{enabled=$true}

当我签入iis管理控制台(UI)时,我可以看到虽然我将值“已启用”更改为“ True ”,但未启用日志记录< / p>

要检查的命令:

(GI IIS:\Sites\$webSiteToEnableLogs).logfile

输出:

logExtFileFlags      : Date,Time,ClientIP,UserName,ComputerName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,TimeTaken,ServerPort,UserAgent,Host,HttpSubStatus
customLogPluginClsid : 
logFormat            : W3C
directory            : E:\IISLog
period               : Weekly
truncateSize         : 20971520
localTimeRollover    : False
enabled              : True
PSComputerName       : #################
RunspaceId           : #######-#######-##########-#######
Attributes           : {Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute, Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute, Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute, Mi
                       crosoft.IIs.PowerShell.Framework.ConfigurationAttribute...}
ChildElements        : {}
ElementTagName       : logFile
Methods              : 
Schema               : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

所有其他参数(例如:日志目录“)已成功更改,但未启用iis

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

在powershell中运行:

C:\ windows \ system32 \ inetsrv \ appcmd 解锁配置-section:system.webServer/httplogging

set-WebConfigurationProperty -PSPath "IIS:\Sites\$webSiteToEnableLogs" -filter "system.webServer/httpLogging" -name dontLog -value $false