Re: Writing an exception log an opening it with Notepad.exe
- From: Benny Raymond <benny@xxxxxxxxxxxxxxx>
- Date: Wed, 28 Dec 2005 16:54:49 -0500
Look at Process.Start
RSH wrote:
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
.
- Follow-Ups:
- References:
- Prev by Date: Re: Help with creating license code
- Next by Date: Re: Can you write code directly in CIL ???
- Previous by thread: Writing an exception log an opening it with Notepad.exe
- Next by thread: Re: Writing an exception log an opening it with Notepad.exe
- Index(es):
Relevant Pages
|