G
Guest
I am trying to build a generic system for tracking unhandled errors which
will place such errors into a log file and the event log. The code is listed
below. When I try to run this code below, I get the error message "The source
was not found, but some or all event logs could not be searched."
The error message occurs when I run the first Trace.WriteLine. Any help you
can offer would be fantastic.
Taylor
try
{
// Log the error to AppLog file
FileStream objStream = new FileStream(current.Page.MapPath("") +
"\\AppLog.txt", FileMode.OpenOrCreate);
TextWriterTraceListener objTraceListener = new
TextWriterTraceListener(objStream);
Trace.Listeners.Add(objTraceListener);
EventLog oLog = new EventLog();
oLog.Source = "CardioManager";
EventLogTraceListener oTraceListener = new EventLogTraceListener();
oTraceListener.EventLog = oLog;
Trace.Listeners.Add(oTraceListener);
Trace.WriteLine("Hello 15Seconds Reader -- This is first trace message");
Trace.WriteLine("Hello again -- This is second trace message");
Debug.WriteLine("Hello again -- This is first debug message");
Trace.Flush();
Trace.Close();
objStream.Close();
}
catch(Exception e)
{
// Untrappable error
int x = 1;
}
finally
{
Trace.Close();
}
will place such errors into a log file and the event log. The code is listed
below. When I try to run this code below, I get the error message "The source
was not found, but some or all event logs could not be searched."
The error message occurs when I run the first Trace.WriteLine. Any help you
can offer would be fantastic.
Taylor
try
{
// Log the error to AppLog file
FileStream objStream = new FileStream(current.Page.MapPath("") +
"\\AppLog.txt", FileMode.OpenOrCreate);
TextWriterTraceListener objTraceListener = new
TextWriterTraceListener(objStream);
Trace.Listeners.Add(objTraceListener);
EventLog oLog = new EventLog();
oLog.Source = "CardioManager";
EventLogTraceListener oTraceListener = new EventLogTraceListener();
oTraceListener.EventLog = oLog;
Trace.Listeners.Add(oTraceListener);
Trace.WriteLine("Hello 15Seconds Reader -- This is first trace message");
Trace.WriteLine("Hello again -- This is second trace message");
Debug.WriteLine("Hello again -- This is first debug message");
Trace.Flush();
Trace.Close();
objStream.Close();
}
catch(Exception e)
{
// Untrappable error
int x = 1;
}
finally
{
Trace.Close();
}