Writing an exception log an opening it with Notepad.exe

R

RSH

Hi all,

I have a situation where I am looping through a DataTable and extracting
values from that DataTable and inserting them into a SQL database. The
application works fine but now I want to add an exception log to the
application. So, I added an Exception handling routine that basically has a
running string that adds errors to the string if they happen. I have three
questions:

1. If a SQL exception happens I would like it to write it to the
ErrorString and then continue to the next record (kind of like the old
Resume Next in VB).

2. When the application finishes running and there is an error in the error
string I would like to write the error to a text file in the application
path and then open the file using NotePad.exe.

3. How do I find the Application Path?



Exception Handling Code Excerpt:

catch (Exception e)

{

strError += "[DATA TRANSFER ERROR][Error: " + e.Message + "][Record Number:
" + iGlobalRecordProgress + "]";

// Resume Next

}


At the end of the application I detect if an error has occured:

if (strError.Length > 1)

{

TextWriter tw = new StreamWriter("DataImportErrorLog-" + DateTime.Now +
".txt");

tw.WriteLine(strError);

tw.Close();

DialogResult result = MessageBox.Show("Errors occurred during the data
transfer. Would you like to view the Error Log now?", "Confirm",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

if (result == DialogResult.OK)

{

// Open Error Log file with Notepad.exe

}


How do I go about that?

Thanks!
Ron
 
M

mwolf

path: AppDomain.CurrentDomain.BaseDirectory

for execution see System.Diagnostics.Process


hope it helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top