problem trying to write to the event log

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi having problems writing to the event log, I have the code below,
using System.Diagnostics;
System.Diagnostics.EventLog myEventLog = new System.Diagnostics.EventLog();
myEventLog.Log="newlog";
myEventLog.Source="newlog";
myEventLog.WriteEntry("another entry");
//this works but when I try
myEventLog.WriteEntry("Consoleapp1","testmessage",EventLogEntryType.Warning)
I get a compiler error-Static member 'member' cannot be accessed with an
instance reference; qualify it with a type name instead
so I tried
System.Diagnostics.EventLog.WriteEntry("Consoleapp1","testmessage",EventLogEntryType.Warning );
this builds ok but does not seem to write to the event.
thanks.
 
Hi Paul,
The problem is that you are specifying "Consoleapp1" as the first parameter,
yet you registered the source as "newLog".

The way you have it written, you are writing to the Application log since it
can't find the Consoleapp1 log.

Change "Consoleapp1" to "newLog" and you will be in business.

Tom Clement
Apptero, Inc.
 
Hi Tom, thanks for the information, working now.

Tom Clement said:
Hi Paul,
The problem is that you are specifying "Consoleapp1" as the first parameter,
yet you registered the source as "newLog".

The way you have it written, you are writing to the Application log since it
can't find the Consoleapp1 log.

Change "Consoleapp1" to "newLog" and you will be in business.

Tom Clement
Apptero, Inc.
 
Back
Top