Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi developers,


In my application I am creating Error log, Event log, Warning log and information Log for every process in text file.

Now I written a function to file write and I am calling every time :(( .
But code is become so large. Is there any option to optimize this code???

Regards,
Nanda
Posted
Comments
Sandeep Mewara 3-Mar-11 2:32am    
It's your code, wihtout looking how come someone can suggest optimization?
Sergey Alexandrovich Kryukov 3-Mar-11 3:06am    
Right, how this is possible?
--SA
thatraja 3-Mar-11 3:10am    
Show your code man
Nanda_MR 3-Mar-11 3:35am    
Guys that general code.

take look

Private Sub BtnGenerate(ByVal Msg As String)
Dim fs As New FileStream(Application.StartupPath & "\MailInfo.Config", FileMode.Append, FileAccess.Write)
Dim d1 As New StreamWriter(fs)
d1.WriteLine("ERROR: " Msg & " " & now)
d1.Close()
End Sub

This function I am calling in many places.
call BtnGenerate("Login Validation Failed")

1 solution

See if the past discussion can help you, I offer a useful class for custom event log: MsBuild OutPut to the TextBox on the fly in Windows Application[^].

Another Answer provides a class to log into the System Log with custom node: How to create event log under a folder[^].

Yes, I know it's C#, sorry. If you demand code samples in VB.NET only you won't get much, so understanding at least some C# is really good if you do .NET development.

—SA
 
Share this answer
 
v2
Comments
[no name] 3-Mar-11 3:59am    
Good call My 5.
Sergey Alexandrovich Kryukov 3-Mar-11 10:50am    
Thank you, updated with a reference to my other Answer.
--SA
Nanda_MR 3-Mar-11 6:02am    
Thanks. I read that and I create similar class in VB.NET but how to call that class?
Sergey Alexandrovich Kryukov 3-Mar-11 10:52am    
I added another reference with another class: how to log in the System Log of a special node. It will give you the idea how log is used. You need to read on the class System.Diagnostics.EventLog.
Actual logging is done using this class. You'll find a call sample in help and in my referenced Answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900