How to Identify W3SVC ID for Specific IIS 7.5 Websites in Log File Analysis


22 views

When working with IIS 7.5, you'll notice log files are stored in folders named W3SVC followed by a number (e.g., W3SVC1, W3SVC2) under C:\inetpub\logs\LogFiles. Unlike IIS 6.0 which displayed this mapping clearly, IIS 7.5 requires a different approach to match websites with their corresponding W3SVC IDs.

The most efficient way is to use IIS's built-in command line tool:

%windir%\system32\inetsrv\appcmd.exe list site

This will output all sites with their IDs in format:

SITE "Default Web Site" (id:1,bindings:http/*:80:,state:Started)
SITE "Marketing Site" (id:3,bindings:http/*:8080:,state:Started)

The id value directly corresponds to the W3SVC folder number.

For those preferring PowerShell, try this script:

Import-Module WebAdministration
Get-ChildItem IIS:\Sites | Select-Object Name, ID

Output example:

Name            ID
----            --
Default Web Site 1
API Services     2
Blog             3

If you need this in an application, use ServerManager API:

using Microsoft.Web.Administration;

var serverManager = new ServerManager();
foreach (var site in serverManager.Sites)
{
    Console.WriteLine($"Site: {site.Name}, ID: {site.Id}");
}

Once you have the ID, you can verify the corresponding log folder contains data for your site:

dir C:\inetpub\logs\LogFiles\W3SVC3\*.log

Check the log entries match your site's domain or IP in the cs-host field.

  • Don't confuse Application Pool IDs with Site IDs
  • Recycled sites maintain their original W3SVC ID
  • The ID remains consistent even if you stop/start the site

In IIS 7.5, website logs are stored in individual folders named W3SVC[ID] under C:\inetpub\logs\LogFiles. Each numeric ID corresponds to a specific website in IIS, but this mapping isn't directly visible in the IIS Manager interface.

The most reliable way to find the mapping is through the command line:

C:\Windows\System32\inetsrv\appcmd.exe list site /text:site.id

This will output all sites with their corresponding IDs. For more detailed information including site names:

C:\Windows\System32\inetsrv\appcmd.exe list site

Example output:

SITE "Default Web Site" (id:1, bindings:http/*:80:, state:Started)
SITE "Marketing Site" (id:3, bindings:http/*:8080:, state:Started)

For servers with PowerShell available, you can use:

Import-Module WebAdministration
Get-ChildItem IIS:\Sites | Select-Object Name, ID

Or alternatively:

Get-Website | Format-Table Name, ID, State, PhysicalPath -AutoSize

The mappings are also stored in the Windows Registry:

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009" /v Counter

Note that this method shows performance counters and requires parsing to find the relevant W3SVC entries.

Imagine you have a website called "E-Commerce Platform" showing 404 errors. Here's how you'd find its logs:

  1. Run: appcmd list site "E-Commerce Platform" /text:site.id
  2. If it returns "4", navigate to W3SVC4 folder
  3. Use PowerShell to parse recent errors:
    Select-String -Path "C:\inetpub\logs\LogFiles\W3SVC4\*.log" -Pattern "404"
    

For frequent log checking, consider creating a batch script:

@echo off
set siteName="Your Site Name"
for /f "tokens=3 delims= " %%i in ('appcmd list site %siteName% ^| find "id:"') do set siteID=%%i
echo Logs for %siteName% are in W3SVC%siteID%
pause
  • Site IDs persist across IIS restarts but may change if sites are deleted and recreated
  • Always use elevated command prompt (Run as Administrator)
  • For clustered environments, IDs may differ between servers