Iis – Disable specific W3C Logging Field

iislogging

Is there a command or PS command to disable a specific W3C Logging Field?

I know you can just go to IIS manager and uncheck the box but I have a few hundred servers to do.

Best Answer

There is a powershell command for this:

Set-WebConfigurationProperty

You can generate your command easily in the IIS GUI. Choose the server (top-level of IIS), then Configuration Editor. Go to section 'system.applicationHost/log'. Make your edits, then find the 'Generate Script' link.

Here is a quick example from something I use for our app servers.

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/log/centralW3CLogFile" -name "logExtFileFlags" -value "Date,Time,ClientIP,UserName,SiteName,ComputerName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,TimeTaken,ServerPort,UserAgent,Referer,HttpSubStatus"

If that gives you trouble, you could also use the appcmd tool with something like this (update MySiteName to your IIS site name, and id='6' to the ID of your web site):

C:\windows\system32\inetsrv\Appcmd set config -section:sites /[name='"MySiteName"',id='6'].logFile.logExtFileFlags:Date,Time,ClientIP,UserName,ServerIP,Method,UriStem,HttpStatus,Win32Status,TimeTaken,ServerPort,UserAgent,Cookie,HttpSubStatus 
Related Topic