help.. :( reverse reading of the log file
-
Hi Mike, A process writes on the log file from the oldest date to the latest. I have to extract first the latest ( which is at the end of the log) I have to search for the “warning” or “critical string“ I have a code that reverses the reading of the log file but my problem is, the details next to it was written also in a reverse manner.. like this… 03/03/05 11:34:04: 03/03/05 11:34:04:AC4_PROD_17.XIE1F_LOTSUBPRODUCTHIST. object has grown from 2128 to 2129 extents 03/03/05 11:34:04:AC2_PROD_8.XIE3F_LOTTXNHIST. object has grown from 4700 to 4701 extents 03/03/05 11:34:04:AC2_PROD_8.XIE1F_LOTSUBPRODUCTHIST. object has grown from 5603 to 5604 extents 03/03/05 11:34:04:AC2_PROD_8.XIE2F_LOTPARAMHIST. object has grown from 8351 to 8352 extents 03/03/05 11:34:04:AC2_PROD_8.XIE3F_LOTHIST. object has grown from 3651 to 3652 extents 03/03/05 11:34:04:AC2_PROD_8.XIE1F_ENTITYPARAMHIST. object has grown from 5542 to 5543 extents 03/03/05 11:34:04:ERROR#**** Error: marsprod@cvspwcora010n2:MARS:object_extent_growth:WARNING ERROR Here’s my code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim fs As FileStream = File.Open("\\cvspwcora010\d$\oracle\admin\log\oramon_marsprod.log", FileMode.Open, FileAccess.ReadWrite, System.IO.FileShare.ReadWrite) Dim streamReader As New StreamReader(fs) Dim stringresult As String = streamReader.ReadToEnd Dim arLogLines() As String = stringresult.Split(vbNewLine) Dim i = 0 Dim b = Len(arLogLines(i)) For i = arLogLines.Length - 1 To 0 Step i - 1 ' If InStr(arLogLines(i), "WARNING") Or InStr(arLogLines(i), "CRITICAL") Then Response.Write(" " & arLogLines(i) & "
") ' Response.Write(" " & arLogLines(i) & "
") ' End If Next End Sub anyone? thanks -
Hi Mike, A process writes on the log file from the oldest date to the latest. I have to extract first the latest ( which is at the end of the log) I have to search for the “warning” or “critical string“ I have a code that reverses the reading of the log file but my problem is, the details next to it was written also in a reverse manner.. like this… 03/03/05 11:34:04: 03/03/05 11:34:04:AC4_PROD_17.XIE1F_LOTSUBPRODUCTHIST. object has grown from 2128 to 2129 extents 03/03/05 11:34:04:AC2_PROD_8.XIE3F_LOTTXNHIST. object has grown from 4700 to 4701 extents 03/03/05 11:34:04:AC2_PROD_8.XIE1F_LOTSUBPRODUCTHIST. object has grown from 5603 to 5604 extents 03/03/05 11:34:04:AC2_PROD_8.XIE2F_LOTPARAMHIST. object has grown from 8351 to 8352 extents 03/03/05 11:34:04:AC2_PROD_8.XIE3F_LOTHIST. object has grown from 3651 to 3652 extents 03/03/05 11:34:04:AC2_PROD_8.XIE1F_ENTITYPARAMHIST. object has grown from 5542 to 5543 extents 03/03/05 11:34:04:ERROR#**** Error: marsprod@cvspwcora010n2:MARS:object_extent_growth:WARNING ERROR Here’s my code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim fs As FileStream = File.Open("\\cvspwcora010\d$\oracle\admin\log\oramon_marsprod.log", FileMode.Open, FileAccess.ReadWrite, System.IO.FileShare.ReadWrite) Dim streamReader As New StreamReader(fs) Dim stringresult As String = streamReader.ReadToEnd Dim arLogLines() As String = stringresult.Split(vbNewLine) Dim i = 0 Dim b = Len(arLogLines(i)) For i = arLogLines.Length - 1 To 0 Step i - 1 ' If InStr(arLogLines(i), "WARNING") Or InStr(arLogLines(i), "CRITICAL") Then Response.Write(" " & arLogLines(i) & "
") ' Response.Write(" " & arLogLines(i) & "
") ' End If Next End Sub anyone? thanksYou messed up on the For statement. The Step modifier should be just "-1", not "i-1". Your code should look more like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fs As FileStream = File.Open("\\cvspwcora010\d$\oracle\admin\log\oramon_marsprod.log", _
FileMode.Open, FileAccess.ReadWrite, System.IO.FileShare.ReadWrite)
Dim streamReader As New StreamReader(fs)
Dim stringresult As String = streamReader.ReadToEnd
Dim arLogLines() As String = stringresult.Split(vbNewLine)
Dim i As Integer
Dim b As Integer = Len(arLogLines(i))
For i = arLogLines.Length - 1 To 0 Step -1
If InStr(arLogLines(i), "WARNING") Or InStr(arLogLines(i), "CRITICAL") Then
Response.Write(" " & arLogLines(i) & "
")
End If
Next
End SubYou might also want to consider putting in some Try/Catch blocks around the file stuff in case the file is unavailable for some reason. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You messed up on the For statement. The Step modifier should be just "-1", not "i-1". Your code should look more like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fs As FileStream = File.Open("\\cvspwcora010\d$\oracle\admin\log\oramon_marsprod.log", _
FileMode.Open, FileAccess.ReadWrite, System.IO.FileShare.ReadWrite)
Dim streamReader As New StreamReader(fs)
Dim stringresult As String = streamReader.ReadToEnd
Dim arLogLines() As String = stringresult.Split(vbNewLine)
Dim i As Integer
Dim b As Integer = Len(arLogLines(i))
For i = arLogLines.Length - 1 To 0 Step -1
If InStr(arLogLines(i), "WARNING") Or InStr(arLogLines(i), "CRITICAL") Then
Response.Write(" " & arLogLines(i) & "
")
End If
Next
End SubYou might also want to consider putting in some Try/Catch blocks around the file stuff in case the file is unavailable for some reason. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
thanks Dave.. always been very helpful.. :)