EventLog.WriteEntry fails with error - RRS feed

  • Question

  • Greetings,


    The following snippet fails with an error under Vista:

    Code Snippet

    catch( System.Exception e )


          System.Diagnostics.Trace.TraceError(String.Format("Failed to load export plugin '{0}'.\n{1}.",

                    fiTemp.FullName, e.InnerException.Message));

          EventLog.WriteEntry( Application.ProductName,

                     String.Format( "Failed to load export plugin '{0}'.\n{1}.",

                     fiTemp.FullName, e.InnerException.Message ),

                    EventLogEntryType.Error );



    The error text is: "The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.


    I saw the following, seemingly related post for this error:



    However, we are not creating an event log source, we are simply trying to write an application error event entry.


    There are several places in our .Net code where we do this. What is the recommended best practice for doing this under Vista?


    Thanks in advance,

    Greg Bradburn.

    Thursday, May 3, 2007 6:50 PM

All replies

  • According to the documentation you must first create and configure the event source before using it. Have you done that properly?


    What kind of event is thrown?

    Saturday, May 5, 2007 9:16 PM
  • I've got the exact same problem and I also found that article you refered to. When I try to call the Eventlog.SourceExists method I get this error:


    "source was not found, but some or all event logs could not be searched. Inaccessible logs: Security"

    I've tried to add some EventLogPermission but with no luck




    , PermissionAccess=EventLogPermissionAccess.Administer

    , MachineName=".")]

    Claus Rathje

    Sunday, May 6, 2007 5:54 AM
  • I've found out that the EventLog.SourceExists requires elevated privileges. This can apparently be done with a manifest.


    In the document below in Step Six (How to Create an Embedded an Application Manifest with Microsoft Visual Studio®) it explains how to do that.


    Windows Vista Application Development Requirements for User Account Control Compatibility


    I hope this will solve the problem. I'll return as soon as I've tried it.


    I also found some notes in Aaron Stebner's weblog:

    Some useful things I have learned about Windows Installer and UAC



    Wednesday, May 9, 2007 9:17 AM
  • Thanks for the replies guys,


    You are correct that the sources must be laid down first and this can only be done with elevated permissions.


    We are modifying our apps to use the Microsoft.EnterpriseLibrary Application Block logging stuff so we will be defining our event log sources in the app.config files of our distributable apps.


    Since we will already have the sources defined there, I'm trying to write an installer class that can be used as a custom action to lay down the event log sources. The installer class will need to be able to read the entries from the app.config file for the application being installed.


    So far, I have not been able to figure out how to do this.


    I tried the following code:

    Code Snippet


    public class MyTestInstaller : Installer


       private EventLogInstaller myEventLogInstaller;


       public MyTestInstaller()




       public override void Install(System.Collections.IDictionary stateSaver)




          Configuration config = ConfigurationManager.OpenExeConfiguration(


          if (config != null)


             foreach (ConfigurationSection section in config.Sections)


                LoggingSettings loggingSettings = section as LoggingSettings;

                if (loggingSettings != null)


                   foreach (FormattedEventLogTraceListenerData traceListenerData in 



                      if (!EventLog.SourceExists(traceListenerData.Source))


                          myEventLogInstaller = new EventLogInstaller();

                          myEventLogInstaller.Source = traceListenerData.Source;

                          myEventLogInstaller.Log = traceListenerData.Log;










    But when run inside the installer, it seems to pick up the msiexec.exe.config, not the configuration for the assembly being installed.


    How can I access the app.config settings for the app being installed from within the Installer.Install() method when invoked as a custom action during the installation process?


    Thanks in advance,




    Monday, May 14, 2007 11:00 PM
  • Here is a link to a bug/suggestion report to update MSDN Documentation to reflect the required security for this:




    Thursday, August 16, 2007 2:36 PM