WriteEntry to Event Log Fails

T

TJO

I am creating an EventLog and attempting to write to it using the
following code. The problem is when I inspect the log there in no
entry? Can anyone see what I am doing wrong here?


if (!System.Diagnostics.EventLog.SourceExists("SmartMI"))
{
System.Diagnostics.EventLog.CreateEventSource(
"SmartMI", "SmartMILog");
}



EventLog EventLog1 = new
EventLog("SmartMILog",System.Environment.MachineName, "SmartMI");

string msg = "Foo Bar";

EventLog1.WriteEntry(msg);
 
G

George

To create a Source you must have special permissions.
ASP.NET account does not have those permissions.

Solution is simple. Write small executable with one line
System.Diagnostics.EventLog.CreateEventSource("SmartMI", "SmartMILog");

Have an admin to run it.

Kill this 4 lines from your ASP.NET code
if (!System.Diagnostics.EventLog.SourceExists("SmartMI"))
{
System.Diagnostics.EventLog.CreateEventSource(
"SmartMI", "SmartMILog");
}


George

I am creating an EventLog and attempting to write to it using the
following code. The problem is when I inspect the log there in no
entry? Can anyone see what I am doing wrong here?


if (!System.Diagnostics.EventLog.SourceExists("SmartMI"))
{
System.Diagnostics.EventLog.CreateEventSource(
"SmartMI", "SmartMILog");
}



EventLog EventLog1 = new
EventLog("SmartMILog",System.Environment.MachineName, "SmartMI");

string msg = "Foo Bar";

EventLog1.WriteEntry(msg);
 
T

TJO

Thanks for helping on this but there is some information I should tell
you.
This code resides in a windows application operating under
Administrator role, so permissions are not an issue with this code
sample.

I still don't see my log entries after caling the WriteEntry().
 

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