How to make log of Error messages in my application.

Dear Experts, I have make application using vb.net 2005 and sqlserver 2008, I wan to make a log of all error messages in one of the table. how can i do this please suggest.
mahmood66Asked:
Who is Participating?
 
nepaluzConnect With a Mentor Commented:
from my code above, you only have to add the MessageBox.Show(), e.g
Try
   'your code here
Catch ex As Exception
    Dim LogFile = "C:\MyLog.txt"
       If Not File.Exists(LogFile) Then
           File.WriteAllText(LogFile, String.Join(", ", {TimeOfDay, ex.Message}) & VbCrLF)
       Else
           File.AppendAllText(LogFile, String.Join(", ", {TimeOfDay, ex.Message}) & VbCrLF)
       End If
       MessageBox.Show(ex.Message.ToString)
End Try

Open in new window

0
 
viralypatelCommented:
Use Log4net ... this is a standard logging tool used in many organizations (at least those where I've already worked) ... and it is east to use and well documented.

Link - Log4net
0
 
nepaluzCommented:
enclose your code in Try ...  Catch and log any errors trapped there to a log file,e.g
Try
   'your code here
Catch ex As Exception
    Dim LogFile = "C:\MyLog.txt"
       If Not File.Exists(LogFile) Then
           File.WriteAllText(LogFile, String.Join(", ", {TimeOfDay, ex.Message}) & VbCrLF)
       Else
           File.AppendAllText(LogFile, String.Join(", ", {TimeOfDay, ex.Message}) & VbCrLF)
       End If
End Try

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mahmood66Author Commented:
thanx for support,  is there any way where i can make log  developer given  messages also where he used  MsgBox Command to display some of the message for the front end user.
0
 
nepaluzCommented:
just call the MessageBox.Show() inside the try catch with the error message.
0
 
mahmood66Author Commented:
dear nepaluz: which file i must imports for this code.
and i am using vb.net not C#, so kindly give me code in vb.net syntax.
0
 
mahmood66Author Commented:
done, I am testing it, i will confirm you back.
0
 
mahmood66Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for mahmood66's comment http:/Q_27307247.html#36555455
Assisted answer: 500 points for nepaluz's comment http:/Q_27307247.html#36542251

for the following reason:

its done.
0
 
mahmood66Author Commented:
I wan to make log in the SQL table and your solution is creatign it in the Text file
0
 
mahmood66Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for mahmood66's comment http:/Q_27307247.html#36555455
Assisted answer: 250 points for nepaluz's comment http:/Q_27307247.html#36535472
Assisted answer: 250 points for nepaluz's comment http:/Q_27307247.html#36542251

for the following reason:

the log is creating but in Text file. I want to make it into SQL table. which now I will import it into sql. thanks anyway
0
 
mahmood66Author Commented:
I want to make log in the SQL table and your solution is creatign it in the Text file
0
 
mahmood66Author Commented:
Thanks. log is creating now. I will import that text file into the SQL table now.

thanks anyway
0
All Courses

From novice to tech pro — start learning today.