Asp.net 使用Powershell配置Advance IIS日志时出现问题
本脚本的目标是:Asp.net 使用Powershell配置Advance IIS日志时出现问题,asp.net,powershell,iis,Asp.net,Powershell,Iis,本脚本的目标是: 为每个站点创建一个新文件夹 每天为每个站点创建一个日志 第二个脚本,用于备份/配置特定格式的脚本 停止所有正常日志记录 用于指导的链接: 而您的问题/问题是?我的错误,在某种程度上,上面的工作原理是,它创建了文件结构和日志定义,但它没有显示所有定义都在编辑器中勾选,最重要的是,它没有创建日志文件,您的问题/问题是?我的错误,上面的工作原理是,在某种程度上,它会创建文件结构和日志定义,但不会显示编辑器中的所有定义都被勾选,最重要的是,它不会创建日志文件 # Ensure
- 为每个站点创建一个新文件夹
- 每天为每个站点创建一个日志
- 第二个脚本,用于备份/配置特定格式的脚本
- 停止所有正常日志记录
用于指导的链接:
而您的问题/问题是?我的错误,在某种程度上,上面的工作原理是,它创建了文件结构和日志定义,但它没有显示所有定义都在编辑器中勾选,最重要的是,它没有创建日志文件,您的问题/问题是?我的错误,上面的工作原理是,在某种程度上,它会创建文件结构和日志定义,但不会显示编辑器中的所有定义都被勾选,最重要的是,它不会创建日志文件
# Ensure cmdlets are available
Import-Module WebAdministration
$Websites = (Get-Website).Name
foreach($site in $websites)
{
Stop-Website $site
}
# Disables http logging module
Set-WebConfigurationProperty -Filter system.webServer/httpLogging -PSPath
machine/webroot/apphost -Name dontlog -Value true
# Disables the default advanced logging config
Set-WebConfigurationProperty -Filter "system.webServer/advancedLogging/server
/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']" -name
enabled -value false
# Enable Advanced Logging
Set-WebConfigurationProperty -Filter system.webServer/advancedLogging/server
-PSPath machine/webroot/apphost -Name enabled -Value true
# Move to location to store iis logs
cd C:\inetpub\Logs\Advancedlogs
# Create Folders if required
Foreach($site in $websites)
{
$FoldersPresent = Test-Path "C:\inetpub\logs\AdvancedLogs\$site"
if($FoldersPresent -eq $true)
{
Write-host "Folder exsists"
}
else
{
New-Item -ItemType directory $site
}
}
# Create hash table
$list = @{'Win32Status'='sc-win32-status';'URI-Stem'='cs-uri-stem';
'URI-Querystring'='cs-uri-query';'Time-UTC'='time';'Time-Local'='time-
local';'Take Taken'='TimeTakenMS';'Substatus'='sc-substatus';'Status'='sc-
status';'Site Name'='s-sitename';'Server-IP'='s-ip';'Server Port'='s-port';
'Server Name'='s-computername';'Protocol Version'='cs-version';'Protocol'='c-
protocol';'Method'='cs-method';'Date-UTC'='date';'Date-Local'='date-local';
'ContentPath'='s-contentpath';'Client-IP'='c-ip';'EndRequest-UTC'='EndRequest-
UTC';'Bytes Sent'='sc-bytes';'Bytes Received'='cs-bytes';'BeginRequest-
UTC'='BeginRequest-UTC';'UserName'='cs-username';'User Agent'='cs(User-
Agent)';'Referer'='cs(Referer)';'Proxy'='s-proxy';'Host'='cs(Host)';
'Cookie'='cs(Cookie)'}
# Set the log file fields
foreach($site in $Websites)
{
$AppName = $site
$appdrive = "C:\inetpub\logs\AdvancedLogs\$site"
$LogRotateFreq = "Daily"
Add-WebConfiguration /system.webServer/advancedLogging/Server
/logDefinitions IIS:\ -Location $AppName -value
@{baseFileName="%COMPUTERNAME%-$AppName";enabled="true";
logRollOption="Schedule";schedule=$LogRotateFreq;publishLogEvent="false"}
$list.GetEnumerator() | foreach {
Add-WebConfiguration "/system.webServer/advancedLogging/Server/logDefinitions/logDefinition[@baseFileName=""%COMPUTERNAME%-$AppName""]/selectedFields" IIS:\ -Location $AppName -value @{defaultValue="";required="false";logHeaderName=$_.Name;id=$_.Value;}
Set-WebConfiguration "/system.applicationHost/Sites/Site[@name=""$AppName""]/advancedLogging" -value @{directory="$appdrive"}
}
}
# Start the websites
foreach($site in $websites)
{
Start-Website $site
}