Hello guys and gals,
I was recently tasked with the really, really stupid job of rewriting IIS logs to show the hits such as "/home/sites/webpart1/default.aspx" as "/home/Default-Web-Part".. a.k.a URL "Friendly names" for clients to understand.
so i decided to make a lightweight application that will extract the data inside a log file and rewrite it to a different directory(for reasons of there are other sites in the log file that i dont want to risk messing with their data).
The problem im running into is replacing the text in vb. I have many different url strings i need to replace, and im not really sure how to do it. So far i got this working with this code:
Any ideas on how i can accomplish what i need to do?
I was recently tasked with the really, really stupid job of rewriting IIS logs to show the hits such as "/home/sites/webpart1/default.aspx" as "/home/Default-Web-Part".. a.k.a URL "Friendly names" for clients to understand.
so i decided to make a lightweight application that will extract the data inside a log file and rewrite it to a different directory(for reasons of there are other sites in the log file that i dont want to risk messing with their data).
The problem im running into is replacing the text in vb. I have many different url strings i need to replace, and im not really sure how to do it. So far i got this working with this code:
VB.NET:
Dim _24HoursAgo As Date = Date.Now.AddHours(-900)
For Each file1 As IO.FileInfo In (New IO.DirectoryInfo("c:\testlog\")).GetFiles("ex080214.LOG_2")
If file1.LastAccessTime >= _24HoursAgo Then
Dim strfile As String = file1.Name
Dim reader1 As String
Dim reader As StreamReader = File.OpenText("c:\testlog\" & strfile)
Dim contents As String = reader.ReadToEnd()
Dim output As String
output = contents
Dim objnew**** As String
objnew**** = contents.Replace("/home/sites/webpart1/default.aspx", "home/Default-Landing-Page")
Dim strOutputFile = "c:\testlog2\" & strfile
Dim objFileSystem = CreateObject("Scripting.fileSystemObject")
Dim objOutputFile = objFileSystem.CreateTextFile(strOutputFile, True)
objOutputFile.Close()
objFileSystem = Nothing
objOutputFile = Nothing
Dim objwriter As StreamWriter
objwriter = File.AppendText("c:\testlog2" & strfile)
Const OPEN_FILE_FOR_APPENDING = 8
' generate a filename base on the script name
Dim strOutputFile2 = "c:\testlog2\" & strfile
objFileSystem = CreateObject("Scripting.fileSystemObject")
objOutputFile = objFileSystem.OpenTextFile(strOutputFile2, _
OPEN_FILE_FOR_APPENDING)
objwriter.Flush()
objOutputFile.WriteLine(objnew****)
objOutputFile.Close()
objFileSystem = Nothing
reader.Close()
MsgBox(objnew****)
End If
Next file1