Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 369dda0

Browse files
Change logging settings
1 parent 6736b7c commit 369dda0

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

‎examples/09-ChangeLogging/IIS.ps1‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -----------------------------------------------------------------------------
2+
# Setup
3+
# -----------------------------------------------------------------------------
4+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
cd $here
6+
7+
. ..\_Setup.IIS.ps1
8+
9+
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10+
mkdir "C:\Sites\Logs" -ErrorAction SilentlyContinue
11+
12+
$manager = Get-IISServerManager
13+
$manager.Sites.Add("Website1", "http", "*:8022:", "C:\Sites\Website1")
14+
$manager.CommitChanges()
15+
16+
# -----------------------------------------------------------------------------
17+
# Example
18+
# -----------------------------------------------------------------------------
19+
Import-Module IISAdministration
20+
21+
$manager = Get-IISServerManager
22+
23+
$site = $manager.Sites["Website1"]
24+
$logFile = $site.LogFile
25+
$logFile.LogFormat = "W3c" # Formats: W3c, Iis, Ncsa, Custom
26+
$logFile.Directory = "C:\Sites\Logs"
27+
$logFile.Enabled = $true
28+
$logFile.Period = "Daily"
29+
30+
$manager.CommitChanges()
31+
32+
# -----------------------------------------------------------------------------
33+
# Assert
34+
# -----------------------------------------------------------------------------
35+
if ($manager.Sites["Website1"].LogFile.Directory -ne "C:\Sites\Logs") { Write-Error "Our logic is wrong" }
36+
37+
# -----------------------------------------------------------------------------
38+
# Clean up
39+
# -----------------------------------------------------------------------------
40+
41+
. ..\_Teardown.IIS.ps1
42+
43+
Remove-IISSite -Name "Website1" -Confirm:$false

‎examples/09-ChangeLogging/README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Changing logging settings
2+
3+
HTTP request logging is provided by IIS and can be specified server-wide or on an individual site level. Applications and virtual directories can disable logging, but they can't do any logging of their own. The examples below show how to set logging at the site level.
4+
5+
Logging settings are stored in `applicationHost.config` underneath the site:
6+
7+
```xml
8+
<system.applicationHost>
9+
<!-- ... -->
10+
<sites>
11+
<site name="Default Web Site" id="1">
12+
<bindings>
13+
<binding protocol="http" bindingInformation="*:80:" />
14+
</bindings>
15+
<logFile logFormat="IIS" directory="%SystemDrive%\inetpub\logs\LogFiles1" period="Hourly" />
16+
</site>
17+
<siteDefaults>
18+
<logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" />
19+
<traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" />
20+
</siteDefaults>
21+
<!-- ... -->
22+
```

‎examples/09-ChangeLogging/Web.ps1‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -----------------------------------------------------------------------------
2+
# Setup
3+
# -----------------------------------------------------------------------------
4+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
cd $here
6+
7+
. ..\_Setup.Web.ps1
8+
9+
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10+
mkdir "C:\Sites\Logs" -ErrorAction SilentlyContinue
11+
12+
New-Website -Name "Website1" -Port 80 -IPAddress "*" -HostHeader "" -PhysicalPath "C:\Sites\Website1"
13+
14+
# -----------------------------------------------------------------------------
15+
# Example
16+
# -----------------------------------------------------------------------------
17+
18+
Import-Module WebAdministration
19+
20+
$settings = @{ `
21+
logFormat="W3c"; ` # Formats: W3c, Iis, Ncsa, Custom
22+
enabled=$true; `
23+
directory="C:\Sites\Logs"; `
24+
period="Daily"; `
25+
}
26+
27+
Set-ItemProperty "IIS:\Sites\Website1" -name "logFile" -value $settings
28+
29+
# -----------------------------------------------------------------------------
30+
# Assert
31+
# -----------------------------------------------------------------------------
32+
33+
if ((Get-ItemProperty "IIS:\Sites\Website1" -name "logFile.directory") -ne "C:\Sites\Logs") { Write-Error "Our logic is wrong" }
34+
35+
# -----------------------------------------------------------------------------
36+
# Clean up
37+
# -----------------------------------------------------------------------------
38+
39+
. ..\_Teardown.Web.ps1
40+
41+
Remove-Item -Path "IIS:\Sites\Website1" -Recurse -Force

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /