The Internet Information Services (IIS) web server provides a secure, easy-to-manage, modular, and extensible platform for reliably hosting websites, services, and applications. With IIS you can share information with users on the Internet, an intranet, or an extranet. IIS is a unified web platform that integrates IIS, ASP.NET, FTP services, PHP, and Windows Communication Foundation (WCF).
IIS web servers generate a massive amount of raw and unfiltered logs every day. IIS logs provide performance, operational, security, and business insights. With the help of these insights, development teams analyze various aspects of server and user activities, such as the time taken to complete a request, the total volume of data sent or received by the server, the HTTP status code to determine server response, and user behavior on a website.
We create PowerShell script that will
1. Extract the log files in the /httplog folder (which I periodically FTP from the Production
environment) and subsequently move the processed files to the /httplog/archive folder
2. Import the log files using the LogParser utility.
3. Remove the log files from the /httplog folder (to avoid inserting duplicate data the
next time the script is run) and also hard-delete the processed files that are 21 days old
4. Parse “User-Agent” field to understand client device and browser details
5. Automate the PS script to run daily in Windows Task Scheduler
Quickstarts | Courtesy Links |
Turn on IIS Loggings (follow below screenshot) | Windows > Internet Information Services (IIS) Manager |
IIS W3C fields metadata | https://docs.microsoft.com/en-us/windows/win32/http/w3c-logging https://www.alibabacloud.com/help/en/doc-detail/84813.html |
HTTP status/error code/desc | https://docs.microsoft.com/en-us/troubleshoot/iis/http-status-code https://www.restapitutorial.com/httpstatuscodes.html |
PrerequisiteDownload the “Log Parser .exe” | https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=24659 |
Find this program at C:\ | C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Log Parser 2.2 |
Powershell script to import website (IIS) logs into SQL Server using Log Parser.You’ll need to update the log files path and connection string in PS script. | ImportWebsiteLogFiles.ps1C:\ |
Create a table in SQL Server | [dbo].[Project_WebLogs] |
Automate the PS script to run daily | Windows > Task Scheduler |
Online code inspiration | https://jonlabelle.com/snippets/view/powershell/import-iis-web-logs-into-sql-using-powershell |
Log Parser Studio (LPS) download for Adhoc/Self Service Reporting | https://techcommunity.microsoft.com/t5/exchange-team-blog/introducing-log-parser-studio/ba-p/601131 |