Go Premium for a chance to win a PS4. Enter to Win

x
Solved

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

Posted on 2011-09-28
Medium Priority
261 Views
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
Question by:Annette Wilson, MSIS

LVL 75

Expert Comment

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

LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 500 total points
ID: 36720392
Dim logFile As New System.IO.StreamWriter("yourPath\yourFile.txt", True)
logFile.WriteLine("hQry2 = 0")
logFile.Close()

0

Author Comment

ID: 36720554
kaufmed:  Text File

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

LVL 75

Assisted Solution

käµfm³d   👽 earned 500 total points
ID: 36772991
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

LVL 17

Expert Comment

ID: 36812803
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

LVL 14

Expert Comment

ID: 36891697
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

Author Closing Comment

ID: 37117964
Thank you.  Sorry I took so long to get back to you.
0

## Featured Post

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
###### Suggested Courses
Course of the Month11 days, 17 hours left to enroll