EventLog logName and source Usage.

J

JimM

I think I am missing something and hopefully someone can set me straight.

I am trying to create an event log with the logName and source arguments.
The logName is always set to MyLog. The source is set to one of several
names, for example: MySource1 and MySource2. I want all the messages to be
in the MyLog folder of the Event Viewer with the source changing by the
application writing the event entry.

Now to create the event log entry I use either the deployment
PojectInstaller class or the EventLog.CreateEventSource method. Both of
these methods get the MyLog folder in the event viewer.

For this example I will use the create method. So the create statements for
both Applications are:

MySource1 application:

EventLog.CreateEventSource( “MySource1â€, “MyLogâ€, “.†);

MySource2 application:

EventLog.CreateEventSource( “MySource2â€, “MyLogâ€, “.†);

After the appropriate programs execute these statements I see the MyLog
folder along with the Application, Security, and System folders. Ok
everything is as expected.

Now I write an event entry using the MySource1 as the source. Then I write
another event for the MySource2. I want both entries in the MyLog folder
when I look in the event viewer.

I use the following statements to write the event entry and I change the
sourceName variable to either MySource1 or MySource2 depending on the
application.

My write code looks like:

Using( EventLog eventLog = new EventLog( “MyLogâ€, “.â€, sourceName )
{
try
{
eventLog.WriteEntry( “My message†);
}
catch( Exception ex )
{
:
}
try
{
eventLog.Close(); // make sure all is flushed to the log.
}
catch( Exception ex )
{
:
}
}

This works as expected and entry is written, but not to the expected folder.
The problem is if I write the MySource1 followed by the MySource2 I see the
MySource1 in the MyLog folder, but the MySource2 is in the Application
folder. The MySource2 always seems to go to the Application folder. What is
going on? If the logName is MyLog the WriteEntry should only write to the
MyLog folder.
 
K

Kevin Yu [MSFT]

Hi Jim,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
M

[MSFT]

Hello Jim,

I test following code on my PC, but get correct results:

EventLog.CreateEventSource("MySource1","MyLog",".");
EventLog.CreateEventSource("MySource2","MyLog",".");

EventLog eventLog1 = new EventLog( "MyLog",".","MySource1" );
EventLog eventLog2 = new EventLog( "MyLog",".","MySource2" );

eventLog1.WriteEntry("log1");
eventLog2.WriteEntry("log2")

Is it possible that the "sourceName" was set to incorrect value in your
real application? You may add its value also in the logged message to check
this.

Luke
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top