dsaydon
dsaydon

Reputation: 4769

Enable iis logging with power shell

I have windows 2008 R2 server with iis 7

I created a script to enable iis logging to a specific web site

I can change the following parameters:

$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"}

I also tried to chnage to $true But also not working

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

When I check in the iis management console (UI) I can see that the logging is not enabled although I changed the value "enabled" to "True"

Command to check:

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

output:

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

All the other parameters (for example: log directory") changed successfully but the iis isn't enabled

Am I missing something?

Upvotes: 3

Views: 3001

Answers (1)

Zhou
Zhou

Reputation: 79

Run in powershell:

C:\windows\system32\inetsrv\appcmd unlock config -section:system.webServer/httplogging

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

Upvotes: 3

Related Questions