EventLog does not write

P

Paperback Writer

Hi, I'm trying to write a eventlog in my Application_Error but does not work
I tryed by using SmtpMail and worked fine, but the EventLog not! =[

The code:

Exception ex = Server.GetLastError().GetBaseException();
string msgErro = ex.Message;
msgErro += "\n" + ex.StackTrace;

// Create the source, if it does not already exist.
if(!System.Diagnostics.EventLog.SourceExists("MySource", "MyServer"))
{
System.Diagnostics.EventLog.CreateEventSource("MySource", "MyNewLog",
"MyServer");
Console.WriteLine("CreatingEventSource");
}

// Create an EventLog instance and assign its source.
System.Diagnostics.EventLog myLog = new System.Diagnostics.EventLog();
myLog.Source = "MySource";

// Write an informational entry to the event log.
myLog.WriteEntry(msgErro);

--

Thanks in advance,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: (e-mail address removed)
 
S

Sambathraj

Hi,
This happens because of permission problems. Create event log source in the
installer class of the application.
Regards
Sambath
 
P

Paperback Writer

Sorry but how do i use this installer class ?

Sambathraj said:
Hi,
This happens because of permission problems. Create event log source in
the installer class of the application.
Regards
Sambath

Cre"Paperback Writer said:
Hi, I'm trying to write a eventlog in my Application_Error but does not
work I tryed by using SmtpMail and worked fine, but the EventLog not! =[

The code:

Exception ex = Server.GetLastError().GetBaseException();
string msgErro = ex.Message;
msgErro += "\n" + ex.StackTrace;

// Create the source, if it does not already exist.
if(!System.Diagnostics.EventLog.SourceExists("MySource", "MyServer"))
{
System.Diagnostics.EventLog.CreateEventSource("MySource", "MyNewLog",
"MyServer");
Console.WriteLine("CreatingEventSource");
}

// Create an EventLog instance and assign its source.
System.Diagnostics.EventLog myLog = new System.Diagnostics.EventLog();
myLog.Source = "MySource";

// Write an informational entry to the event log.
myLog.WriteEntry(msgErro);

--

Thanks in advance,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: (e-mail address removed)
 

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,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top