C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » VB.NET Syntax »

Creating log files of error.


Posted Date: 03 Aug 2009    Resource Type: Code Snippets    Category: VB.NET Syntax
Author: NeetuMember Level: Diamond    
Rating: 1 out of 5Points: 3




In this program whenever error is generated then all the details of the error will be saved in the text file.(similar to log files in windows).




Imports System.IO
Imports System.Text
Imports System
Public Class CError
'FileStream deals with the handling of files. Its supports both reading as well as writing in a file.
Dim fs As FileStream
Public Sub createfile(ByVal path As String, ByVal errormsg As String)

'File.Exists(path) checks whether file exit or not it exists then return true else return false.
If File.Exists(path) = False Then
'File.Create(path) will create the file in specified path
Dim fs As FileStream = File.Create(path)
'UTF8Encoding(True) means Initializes a new instance of the UTF8Encoding class. A parameter specifies whether to prefix an encoding with a Unicode byte order mark.
'UTF8Encoding.GetBytes Encodes the characters from a specified String and returns the results in a byte array.
Dim info As Byte() = New UTF8Encoding(True).GetBytes(errormsg)
'fs.Write(Array() as byte,From where to start for writing in file,how many characters should be write in a file as integer)
fs.Write(info, 0, info.Length)
'fs.close() will close the file.
fs.Close()

Else
'Fs open the existing file and append the error message inside that.
Dim fs As FileStream = File.Open(path, FileMode.Append)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(errormsg)
fs.Write(info, 0, info.Length)
'fs.close() will close the file.
fs.Close()
End If
End Sub
End Class


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try
Dim con As OleDb.OleDbConnection

TextBox1.Text = "E:\Neet Full Data\NEETU (F)\VBNet\Net class\Error Handling\ErrorHNDLING\erreornew.txt"
con.ConnectionString = ""
con.Open()
Catch ex As Exception
Dim filename As New StringBuilder
filename.Append("E:\Neet Full Data\NEETU (F)\VBNet\Net class\Error Handling\ErrorHNDLING\erreornew.txt")
'filename.Append(Date.Today.Date.ToString)
'filename.Append(".txt")
MsgBox(filename.ToString)
Dim str As String = ex.Message + " TIME & DATE " + Date.Now
obj.createfile(filename.ToString, str)

End Try

End Sub


regards
Neetu


Attachments

  • Creating log files of an error. (30991-3610-ErrorHNDLING.rar)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Creation of log files using vb.net  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Checking the perfect square of number
    Previous Resource: Export datatable to excel
    Return to Discussion Resource Index
    Post New Resource
    Category: VB.NET Syntax


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use