Return to Snippet

Revision: 21326
at December 10, 2009 12:35 by mpcircuitry


Initial Code
Public Class ERROR_LOGGING

Public Shared Sub writeError(ByVal sPathName As String, ByVal sErrMsg As String)

        Dim LogFormat As String = DateTime.Now.ToShortDateString & " " & DateTime.Now.ToLongTimeString & " ==> "
        Dim year As String = DateTime.Now.Year.ToString
        Dim month As String = DateTime.Now.Month.ToString
        Dim day As String = DateTime.Now.Day.ToString
        Dim ErrorTime As String = month + "_" + day + "_" + year

        Dim fileName As String = sPathName + ErrorTime + ".log" 'Server.MapPath("TestMsg.txt")

        IO.File.AppendAllText(fileName, LogFormat + sErrMsg + ControlChars.NewLine + ControlChars.NewLine)

    End Sub






End Class



 ' Example on its usage I use it in the global.asx file

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
        Try
            ERROR_LOGGING.writeError(Server.MapPath("~/Logs/ErrorLog/"), Server.GetLastError.Message + Server.GetLastError.InnerException.ToString)
            Response.Redirect("~/security/index.aspx")
        Catch ex As Exception

        End Try
    End Sub

Initial URL


Initial Description


Initial Title
Error Logging Class

Initial Tags
log, Net

Initial Language
VB.NET