Solved

How to make log of Error messages in my application.

Posted on 2011-09-14
12
284 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:mahmood66
  • 8
  • 3
12 Comments
 
LVL 12

Expert Comment

by:viralypatel
ID: 36535426
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
 
LVL 17

Expert Comment

by:nepaluz
ID: 36535472
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
 

Author Comment

by:mahmood66
ID: 36535909
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 17

Expert Comment

by:nepaluz
ID: 36535946
just call the MessageBox.Show() inside the try catch with the error message.
0
 

Author Comment

by:mahmood66
ID: 36542107
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
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 36542251
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
 

Author Comment

by:mahmood66
ID: 36555455
done, I am testing it, i will confirm you back.
0
 

Author Comment

by:mahmood66
ID: 36572824
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
 

Author Comment

by:mahmood66
ID: 36572825
I wan to make log in the SQL table and your solution is creatign it in the Text file
0
 

Author Comment

by:mahmood66
ID: 36572833
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
 

Author Comment

by:mahmood66
ID: 36572834
I want to make log in the SQL table and your solution is creatign it in the Text file
0
 

Author Closing Comment

by:mahmood66
ID: 36572840
Thanks. log is creating now. I will import that text file into the SQL table now.

thanks anyway
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need a starter for ETL protocol? 4 65
How to open form using item in Listbox. 8 23
VB.Net. Reading xml value 6 29
Need syntax help building hyperlink 2 21
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question