C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Writing Log for the applications


Posted Date: 06 May 2008    Resource Type: Code Snippets    Category: Exceptions

Posted By: Dharmaraj       Member Level: Diamond
Rating:     Points: 9



The code sample is an utility to any application. It helps write logs of activities that an application performs. The function, moreover, is generalized to be used with any application.

An application simply calls WriteLog() providing the message and it's destination as it's parameters. Other details like timing of the log are added automatically to the message.

The code also handles exceptions that may occur while file operations are being performed.


Public Sub WriteLog(ByVal logMessage As String, ByVal vFileName As String)
Try
Dim vFullFilePath As String
vFullFilePath = AppDomain.CurrentDomain.BaseDirectory.ToString & "Log\"
Dim dir As New IO.DirectoryInfo(vFullFilePath)
If dir.Exists = False Then dir.Create()
'Format(Date.Now, "d-MMM-yy")
vFullFilePath = vFullFilePath & vFileName & GetDate() & ".txt"
Dim tWrite As IO.TextWriter = IO.File.AppendText(vFullFilePath)
tWrite.WriteLine(DateTime.Now.ToLongDateString() & vbTab & DateTime.Now.ToLongTimeString() & vbTab & logMessage)
' Update the underlying file.
tWrite.Flush()
tWrite.Close()
Catch ex As Exception
End Try
End Sub





Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Writing Logs for Applications  .  Writing Logs  .  Logging activities of an Application  .  

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: How to save application errors(Exceptions occurs) in SQL Server Database
Previous Resource: Logging Exception to Event Log with ASP
Return to Discussion Resource Index
Post New Resource
Category: Exceptions


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use