Home arrow ASP arrow Page 3 - View Your Web Servers Log Files With ASP

View Your Web Servers Log Files With ASP

Mike knows the pain and frustration of having a web server crash unexpectedly... it happens when we least expect it. In this article, he's going to describe a simple way to create an ASP page that will allow us to view our web servers log files in a standard web page across the Internet.

Author Info:
Rating: 5 stars5 stars5 stars5 stars5 stars / 57
December 28, 2001
  1. · View Your Web Servers Log Files With ASP
  2. · Windows 2000 and log files
  3. · The MSWC logging utility
  4. · The ShowLogEntries sub-routine
  5. · Conclusion

print this article

View Your Web Servers Log Files With ASP - The MSWC logging utility
(Page 3 of 5 )

When Windows 2000 server is installed for the first time, a DLL named “logscrpt.dll” is also installed and registered. This DLL contains the MSWC.IISLog class, which allows us to load, read, write and close IIS log files on our server. To create an instance of the MSWC.IISLog class in ASP, we use the “MSWC.IISLog” ProgId, like this:

set objLog = Server.CreateObject("MSWC.IISLog")

The MSWC.IISLog class contains several methods and properties that can be used to either retrieve log entries, or write log entries to a log file. These methods and properties are described below:

  • AtEndOfLog: Indicates whether all records have been read from the log file.
  • CloseLogFiles: Closes all open log files.
  • OpenLogFile: Opens a log file for reading or writing.
  • ReadFilter: Filters records from the log file by date and time.
  • ReadLogRecord: Reads the next available log record from the current log file.
  • WriteLogRecord: Writes a log record to the current log file.
  • BytesReceived: Indicates the number of bytes received.
  • BytesSent: Indicates the number of bytes sent.
  • ClientIP: Indicates the client’s host name.
  • Cookie: Indicates the client’s cookie.
  • CustomFields: Indicates an array of custom headers.
  • DateTime: Indicates the date and time, in GMT.
  • Method: Indicates the operation type.
  • ProtocolStatus: Indicates the protocol status.
  • ProtocolVersion: Indicates the version string.
  • Referer: Indicates the referrer page.
  • ServerIP: Indicates the server’s IP address.
  • ServerName: Indicates the server name.
  • ServerPort: Indicates the port number.
  • ServiceName: Indicates the service name.
  • TimeTaken: Indicates the total processing time.
  • URIQuery: Indicates any parameters passed with the request.
  • URIStem: Indicates the target URL.
  • UserAgent: Indicates the user agent string.
  • UserName: Indicates the user’s name.
  • Win32Status: Indicates the Win32 status code.
We will use some of these methods and properties now, to create our log viewer script, viewlog.asp. This file is available for download as part of the support material for this article. It will contain two sub-routines: GetDetails and ShowLogEntries.

The GetDetails sub-routine will be called automatically whenever the viewlog.asp file is loaded for the first time. Its declaration looks like this:

Sub GetDetails()

It will display a HTML form with one text box, two drop-down lists, and a submit button. The text box will be where the user enters the file name for the log file they wish to view. This file name should contain a physical path, such as “c:\winnt\system32\logfiles\w3svc1\ex012808.log”. The first drop-down list will allow the user to select which type of log file they are viewing. The second drop-down list will allow the user to choose how many records to view.

The code for the GetDetails sub-routine is shown below:

sub GetDetails()

'This sub-routine will display a simple HTML form

'into which the user will enter the location of

'the log file that we will be viewing.


<form name="frmGetFile" action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="post">

<h1>Log File Details</h1>

Please enter the name and full path to the log file

that you would like to view:<br>

<input type="text" name="txtLogFile">


What type of log file will you be viewing?<br>

<select name="txtType">

<option SELECTED>W3C Extended Log File Format</option>

<option>NCSA Common Log File Format</option>

<option>Microsoft IIS Log File Format</option>



How many records do you want returned?<br>

<select name="intRecs">











<option value="10000" SELECTED>ALL</option>



<input type="submit" name="submitted" value="View Log">



end sub

The HTML output from the GetDetails sub-routine looks like this:

The output from the GetDetails sub-routine

Once the user completes the details form and clicks on the “View Log” button, the ShowLogEntries sub-routine is called. I will describe this sub-routine on the next page.
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials