dcsimg
Results 1 to 2 of 2

Thread: How to get system error message in vb page?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    468

    How to get system error message in vb page?

    In web.config I used code below to disable custom errors.

    <customErrors mode="Off" />

    To view errors for debug, I need to call IT to get errors in web server in event viewer.

    If I add code below in web.config which only displays warning message.

    <customErrors mode="RemoteOnly" defaultRedirect="~/GeneralErrorPage.htm" />

    Is there any way to code in vb page to list real error for debug?

    I can't post reply so I have to edit here.
    I got an "No defined" error in LoggingData

    Private Sub LogToDB(ByVal UserCode As String, ByVal ProgramName As String, ByVal MethodName As String, ByVal MessageType As String, ByVal logLine As String)
    Dim logData As LoggingData = New LoggingData()
    logData.CreateLogEntry(connectString, UserCode, ProgramName, MethodName, MessageType, logLine)
    End Sub
    Last edited by aspfun; Mar 1st, 2019 at 08:12 AM.

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,526

    Re: How to get system error message in vb page?

    Really you should be using Logging of some kind to record errors and potentially other information in your web application.

    In my Web apps i have a fairly simple but effective custom error logger which i use in each try catch block to capture any errors and log out. I can log out to either to file or database depending on a property in the web.config.

    I also log out some other information such as whether certain methods are being entered etc in INFO logs.

    here is an example call which i put in the catch block of a try catch and in other place i may want to catch an error or information AppSettings.Lgging is just a string property value either "On" or "Off", AppSettings.LogType is a property with the enum Logtype from the logging class as its type so i can choose to log to file or db.

    Code:
    Log.WriteLogLine(AppSettings.Logging, AppSettings.LogType, usercode.ToString(), "AppName", "MethodName", "Error", "My Error prefix - " & errormessage)
    if i want to log out information instead of an error i just change the log line like this -

    Code:
    Log.WriteLogLine(AppSettings.Logging, AppSettings.LogType, usercode.ToString(), "AppName", "MethodName", "Info", "My Info Message")

    Here is a copy of my base logging class (Converted form C# across to VB.Net) , it takes connectString (db connectionString) and logNamePath (the Log File name & path) as params.

    Code:
    Imports System
    Imports System.IO
    
    Namespace Logging
        Public Enum LogType
            File
            DB
        End Enum
    
        Public Partial Class Logger
            Private logFile As String = ""
            Private connectString As String = ""
    
            Public Sub New(ByVal ConnectString As String, ByVal logNamePath As String)
                logFile = logNamePath
                connectString = ConnectString
            End Sub
    
            Public Sub WriteLogLine(ByVal Logging As String, ByVal logtype As LogType, ByVal ProgramName As String, ByVal MethodName As String, ByVal MessageType As String, ByVal logLine As String)
                If Logging = "On" Then
    
                    If logtype = LogType.File Then
                        LogToFile("NA", MethodName, MessageType, logLine)
                    ElseIf logtype = LogType.DB Then
                        LogToDB("NA", ProgramName, MethodName, MessageType, logLine)
                    End If
                End If
            End Sub
    
            Public Sub WriteLogLine(ByVal Logging As String, ByVal logtype As LogType, ByVal UserCode As String, ByVal ProgramName As String, ByVal MethodName As String, ByVal MessageType As String, ByVal logLine As String)
                If Logging = "On" Then
    
                    If logtype = LogType.File Then
                        LogToFile(UserCode, MethodName, MessageType, logLine)
                    ElseIf logtype = LogType.DB Then
                        LogToDB(UserCode, ProgramName, MethodName, MessageType, logLine)
                    End If
                End If
            End Sub
    
            Private Sub LogToFile(ByVal UserCode As String, ByVal MethodName As String, ByVal MessageType As String, ByVal logLine As String)
                Using w As StreamWriter = File.AppendText(logFile)
                    w.WriteLine(DateTime.Now & " - " & UserCode & " - " & MethodName & " - " & MessageType & " - " & logLine)
                End Using
            End Sub
    
            Private Sub LogToDB(ByVal UserCode As String, ByVal ProgramName As String, ByVal MethodName As String, ByVal MessageType As String, ByVal logLine As String)
                Dim logData As LoggingData = New LoggingData()
                logData.CreateLogEntry(connectString, UserCode, ProgramName, MethodName, MessageType, logLine)
            End Sub
        End Class
    End Namespace
    My LoggingData class that i am calling in the LogToDB method just calls a stored procedure and saves the log info to a logging table
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width