This method allows you to open a log file for reading or writing using the IISLog object.
OIISLog.OpenLogFile( FileName, IOMode, ServiceName, ServiceInstance, OutputLogFileFormat )
Constant | Value | Description |
ForReading | 1 | Opens the specified log file for reading. |
ForWriting | 2 | Opens the specified log file for writing. |
Important
None of the parameters are optional
The following example opens a log file in the W3C Extended Log File Format, and writes its contents to another log file in the NCSA Common Log File Format.
--- Log_OpenFile.asp ---
<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY>
<%
LogFile = Request.Form("logfile")
Output = Request.Form("output")
%>
<H3>Convert From W3C Extended Log Format to NCSA Common Log Format</H3>
<FORM NAME="getlogfilename" METHOD="POST" ACTION="Log_OpenFile.asp">
Please enter the full path name of a log file to read in %SystemRoot%\system32\LogFiles\*SVC*:<BR>
<input type="TEXT" NAME="logfile" size=70 value=<%=LogFile%>><BR>
Enter the full path name of a log file to write to:<BR>
<input type="TEXT" NAME="output" size=70 value=<%=Output%>><BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
<%
''''''''''''''''''''
' Log file formats:
' "NCSA Common Log File Format"
' "Microsoft IIS Log File Format"
' "W3C Extended Log File Format"
'''''''''''''''''''''
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
If fsoObject.FileExists(LogFile) Then
Set oRead = CreateObject ("MSWC.IISLog")
Set oWrite = CreateObject ("MSWC.IISLog")
oRead.OpenLogFile LogFile, 1, "W3SVC", 1, "W3C Extended Log File Format"
oWrite.OpenLogFile Output, 2, "W3SVC", 1, "NCSA Common Log File Format"
oRead.ReadLogRecord
Do While Not oRead.AtEndOfLog
oWrite.WriteLogRecord oRead
oRead.ReadLogRecord
Loop
oRead.CloseLogFiles 1
oWrite.CloseLogFiles 2
Response.Write "File " & LogFile & "<BR>has been written to " & Output & "<BR>"
ElseIf Not (LogFile = "") Then
Response.Write "ERROR: " & LogFile & " does not exist."
End If
%>
</BODY>
</HTML>