Very Easy Question, How to write log to SECURTY Event Log? Please help

  • Thread starter Thread starter John
  • Start date Start date
J

John

Is there any special code I have to write to log event to Security
Event Log? The following code give me "Very Easy Question, How to
write log to SECURTY Event Log? Please help" Error

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

// Write an informational entry to the event log.
myLog.WriteEntry("Writing warning to event log.",
EventLogEntryType.Warning);


but as soon as I change "Security" to "Application" ,
everything works fine

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

// Write an informational entry to the event log.
myLog.WriteEntry("Writing warning to event log.",
EventLogEntryType.Warning);


Any ideas?
Thanks in advance
John
 
John,

What happens when you try and write to the security event log? Do you
get an exception or something of that nature? If so, what is it?
 
Only administrator can read from the security log, but user programs cannot
write to the security log, this is a privilege of the security subsystem
only.

Willy.

| Is there any special code I have to write to log event to Security
| Event Log? The following code give me "Very Easy Question, How to
| write log to SECURTY Event Log? Please help" Error
|
| // Create an EventLog instance and assign its source.
| EventLog myLog = new EventLog();
| myLog.Source = "Security";
|
| // Write an informational entry to the event log.
| myLog.WriteEntry("Writing warning to event log.",
| EventLogEntryType.Warning);
|
|
| but as soon as I change "Security" to "Application" ,
| everything works fine
|
| // Create an EventLog instance and assign its source.
| EventLog myLog = new EventLog();
| myLog.Source = "Application";
|
| // Write an informational entry to the event log.
| myLog.WriteEntry("Writing warning to event log.",
| EventLogEntryType.Warning);
|
|
| Any ideas?
| Thanks in advance
| John
|
 
if throw exception the following exception:

Cannot open log for source 'Security'. You may not have write access.

John,

What happens when you try and write to the security event log? Do you
get an exception or something of that nature? If so, what is it?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John said:
Is there any special code I have to write to log event to Security
Event Log? The following code give me "Very Easy Question, How to
write log to SECURTY Event Log? Please help" Error

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

// Write an informational entry to the event log.
myLog.WriteEntry("Writing warning to event log.",
EventLogEntryType.Warning);


but as soon as I change "Security" to "Application" ,
everything works fine

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

// Write an informational entry to the event log.
myLog.WriteEntry("Writing warning to event log.",
EventLogEntryType.Warning);


Any ideas?
Thanks in advance
John
 
True. As I said in my previous answer, you can't write to the Security log
from user code. Even the code as presented in the article needs elevated
privileges to register a provider and the program needs to run with
'SeAuditingPrivileges' enabled, something you don't want to do from regular
user applications, only very security conscious services need this.
Why do you want to write to the security log anyway, applications and
services should write to the 'Application' log or a private log.

Willy.


| Looks like it only works for WIndows 2003, not Windox XP
|
 
Back
Top