2

I am attempting to create my own custom event log using the below code:

 if (!System.Diagnostics.EventLog.SourceExists("DataStream"))
            {
                EventLog.CreateEventSource("DataStream", "SIRsDetectionDataStreamLog");
            }
            logger = new EventLog();
            logger.Source = "DataStream";

However, I keep getting a security error when checking if the source exists. The error I get is as follows:

SecurityException was unhandled

An unhandled exception of type 'System.Security.SecurityException' occurred in System.dll

Additional information: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
2
  • Read the documentation: msdn.microsoft.com/en-us/library/vstudio/…. SecurityException: source was not found, but some or all of the event logs could not be searched. i.e. you need to be administrator. Commented Jan 16, 2015 at 21:30
  • 1
    Consider creating the event log when the service is installed. You have to be an administrator to install a service. You would either do this in a service installer using EventLogInstaller or in your MSI using something like WiX's EventSource component. Commented Jan 16, 2015 at 23:41

1 Answer 1

3

To create an event source you must have administrative privileges.

All event logs, including the security log, must be searched to determine whether the event source is unique. Non administrative users do not have permission to access the security log therefore a SecurityException is thrown.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.