iis - 使用 Powershell 添加 IIS 8.5 自定义日志记录字段

标签 iis powershell

带有 IIS 8.5 的 Windows Server 2012 R2 允许使用增强日志记录的自定义日志字段

http://www.iis.net/learn/get-started/whats-new-in-iis-85/enhanced-logging-for-iis85

我想用 Powershell 添加字段

以下工作:

Set-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection -value
 @{logFieldName='foo';sourceType='RequestHeader';sourceName='c-ip'}

但我无法向 logfile.customFields.collection 添加第二个条目 它请求 -Force 并覆盖现有条目

我通过 GUI 添加了 2 来说明问题
Get-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection

logFieldName   : foo
sourceName     : c-ip
sourceType     : RequestHeader
Attributes     : {logFieldName, sourceName, sourceType}
ChildElements  : {}
ElementTagName : add
Methods        :
Schema         : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

logFieldName   : foo2
sourceName     : c-servername
sourceType     : RequestHeader
Attributes     : {logFieldName, sourceName, sourceType}
ChildElements  : {}
ElementTagName : add
Methods        :
Schema         : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

logFieldName、sourceName 和 sourceType 是同名的 NoteProperty 成员

如何在 Powershell 中执行此操作?

最佳答案

IIS Forums上的一个用户回答

   New-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection -value
         @{logFieldName='foo';sourceType='RequestHeader';sourceName='c-ip'}

   New-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection -value
         @{logFieldName='foo2';sourceType='RequestHeader';sourceName='c-ip'}

我确认这确实有效

关于iis - 使用 Powershell 添加 IIS 8.5 自定义日志记录字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18992990/

相关文章:

php - IIS+PHP+MySQL : A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)

git - 获取 Git 中两次提交之间修改次数最多的文件

powershell - 如何抑制 PowerShell Get-Content 输出

asp.net - 您可以通过 SSL 在单个 ASP.NET 应用程序实例上托管多个租户吗?

asp.net - 运行计划任务的最佳方式

IIS 重写问题 - 捕获所有 .php 文件

asp.net - 在Application_Start和Application_End中调用SqlConnection.ClearAllPools()?

powershell - 如何防止将 Powershell 模块安装到 OneDrive 中

powershell - 如何在powershell中忽略foreach中的空值?

带有 UiPath 的 Powershell