x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 275

# Create Log Files: ASP.NET VB, SQL 2005

I have created a console application as part of a data integration solution.  In my code, I'm currently writing errors to console.  I would like to create a text log file and write errors to it as well as the application completed time.

how do I create log files in vb.net?

Dim hQry2 As Integer = oAPI.AmQueryCreate(intConn)
If (hQry2 = 0) Then
Console.WriteLine("hQry2 = 0")  Write to a log file
End If
0
Annette Wilson, MSIS
2 Solutions

Commented:
When you say "log files", are you referring to the Event Log, or just a flat text file?
0

PresidentCommented:
Dim logFile As New System.IO.StreamWriter("yourPath\yourFile.txt", True)
logFile.WriteLine("hQry2 = 0")
logFile.Close()

0

Sr. Programmer AnalystAuthor Commented:
kaufmed:  Text File

JamesBurger:  Thank you.... I'll try this and get back to you.
0

Commented:
You could also do it with one line. It is, of course, a matter of design and preference:
System.IO.File.AppendAllText("C:\path\to\log\file.txt", "hQry2 = 0")

0

There is cool log4net to write all types of log. You just need to configure and log the error

Check this.
http://www.codeproject.com/KB/aspnet/Log4Net_Configuration.aspx
0

Commented:
I use NLog.  No need to re-invent the wheel per say as the dudes at NLog have done a phenomenal job with the library and allow you to do pretty much any type of logging you would want to.  Everything is setup in an NLog.config file.

http://nlog-project.org/
0

Sr. Programmer AnalystAuthor Commented:
Thank you.  Sorry I took so long to get back to you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.