Attempted EventLog Trace triggers error

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();


}
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top