creating EventLog code, is this code correct?

J

Jeff

hi

..Net 2.0

I've created the code below and think I've executed it. After I thought I've
executed it I checked in EventLog on the computer (win2k3) and no entry was
added. This could mean 2 things:
- There are some logical errors in my code
- The code wasn't actually executed

string Log = "MIIS_AH";
if ((!(EventLog.SourceExists(Log))))
{
EventLog.CreateEventSource(Log, Log);
}
EventLog logEntry = new EventLog();
logEntry.Source = Log;
logEntry.WriteEntry("HELLOWORLD");

This code is part of a method with more code inside it. Below I've posted
more of that method just in case you need to see it (MIIS 2003, Provisioning
code). I have some problems with this code, no Connector Space objects are
created (not important what that is), so I added the EventLog code you see
above to my code for the purpose of debugging my code (I wanted to see if my
code actually was executed). As I've heard that I cannot use breakpoints in
the code here. Cannot as this code will be compiled to a .dll which MIIS
(microosft integrated indentry server) will execute. As far as I know it
won't execute debug code. But would be great if I'm wrong about it, as then
I've learned something new ;)

you see any reason why the eventlog code wasn't executed?

CSEntry csentry;
ConnectedMA connectedMA = mventry.ConnectedMAs["Bil 2"];
if (connectedMA.Connectors.Count == 0)
{
csentry = connectedMA.Connectors.StartNewConnector("Bil");
csentry.DN = connectedMA.CreateDN("id");
csentry["Bileier"].Values.Add(mventry["Bileier"].Value);
csentry["Bilmerke"].Values.Add(mventry["Bilmerke"].Value);
csentry.CommitNewConnector();
string Log = "MIIS_AH";
if ((!(EventLog.SourceExists(Log))))
{
EventLog.CreateEventSource(Log, Log);
}

EventLog logEntry = new EventLog();
logEntry.Source = Log;
logEntry.WriteEntry("HELLOWORLD");
}
 
I

Ignacio Machin ( .NET/ C# MVP )

hi

.Net 2.0

I've created the code below and think I've executed it. After I thought I've
executed it I checked in EventLog on the computer (win2k3) and no entry was
added. This could mean 2 things:
- There are some logical errors in my code
- The code wasn't actually executed

string Log = "MIIS_AH";
if ((!(EventLog.SourceExists(Log))))
{
EventLog.CreateEventSource(Log, Log);}

EventLog logEntry = new EventLog();
logEntry.Source = Log;
logEntry.WriteEntry("HELLOWORLD");

from seeing it it seems ok, did you see the examples in msdn lib?

Just a dumb question, did you do a refresh in the event log?
do you at least see the new log you are creating?

This code is part of a method with more code inside it. Below I've posted
more of that method just in case you need to see it (MIIS 2003, Provisioning
code). I have some problems with this code, no Connector Space objects are
created (not important what that is), so I added the EventLog code you see
above to my code for the purpose of debugging my code (I wanted to see ifmy
code actually was executed). As I've heard that I cannot use breakpoints in
the code here. Cannot as this code will be compiled to a .dll which MIIS
(microosft integrated indentry server) will execute. As far as I know it
won't execute debug code. But would be great if I'm wrong about it, as then
I've learned something new ;)

you see any reason why the eventlog code wasn't executed?

Maybe you get an exception before the code is executed.
Why don't you first use a file log. and handle all the unhandle
exceptions event
 

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