SNB Solutions - Baja California Software Company
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Catching page level errors and writing them in log file with auto controlled file size
stoian_bycovich
#1 Posted : Friday, February 26, 2010 2:47:31 PM

Rank: Administration

Medals:

Groups: Administrators
Joined: 1/2/2010
Posts: 79
Points: 10,237
Location: Cabo San Lucas

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
This is preaty handy for catching page errors and writing them down in log file which is automaticaly deleted if he reaches defined file size.

Imports System.IO



Public Shared Sub PageErr(ByVal ErrorMessage As String, ByVal UserIPAddress As String, _
ByVal URLRefferer As String, ByVal PathToLogFile As String, _

ByVal FileMaxSize As Integer, ByVal FileName As String)
Dim fileExists As Boolean = My.Computer.FileSystem.FileExists(PathToLogFile & FileName)

If fileExists = False Then

Try

My.Computer.FileSystem.WriteAllText(PathToLogFile & FileName, "File created: " & DateTime.Now.ToString, False)
My.Computer.FileSystem.WriteAllText(PathToLogFile & FileName, _

vbCrLf & vbCrLf & "/**************************** " & DateTime.Now.ToString & " ********************************/" & _
vbCrLf & "Error level: Page level" & _

vbCrLf & "Error message: " & ErrorMessage & _
vbCrLf & "URL refferer: " & URLRefferer & _

vbCrLf & "Users' IP: " & UserIPAddress, True)
Catch ex As Exception

End Try

Else

Dim fileSize As Long = My.Computer.FileSystem.GetFileInfo(PathToLogFile & FileName).Length()
If fileSize >= FileMaxSize Then

Try

My.Computer.FileSystem.DeleteFile(PathToLogFile & FileName, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
My.Computer.FileSystem.WriteAllText(PathToLogFile & FileName, "File created: " & DateTime.Now.ToString, False)

My.Computer.FileSystem.WriteAllText(PathToLogFile & FileName, _
vbCrLf & vbCrLf & "/**************************** " & DateTime.Now.ToString & " ********************************/" & _

vbCrLf & "Error level: Page level" & _
vbCrLf & "Error message: " & ErrorMessage & _

vbCrLf & "URL refferer: " & URLRefferer & _
vbCrLf & "Users' IP: " & UserIPAddress, True)

Catch ex As Exception
End Try

Else

My.Computer.FileSystem.WriteAllText(PathToLogFile & FileName, _
vbCrLf & vbCrLf & "/**************************** " & DateTime.Now.ToString & " ********************************/" & _

vbCrLf & "Error level: Page level" & _
vbCrLf & "Error message: " & ErrorMessage & _

vbCrLf & "URL refferer: " & URLRefferer & _
vbCrLf & "Users' IP: " & UserIPAddress, True)

End If

End If

End Sub



Just pass the aguments and make sure that aspnet user has apropriate read write permissions over the folder where you are going to store the log file

Hope it helps
Best regards,
Stoyan Bukovich
Executive manager
SNB Solutions

Cell.: +52 6241 616969
E-mail: s.bucovich@snb-bg.com
Web: www.snb-bg.com
Sponsor  
 
Eannouncements.net SNB Solutions Eanuncios.net

Eannouncements.net the place for your announcement.

SNB Solutions - Software and computing services company.

Eanuncios.net el lugar para su anuncio.

Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.