locked
CreateEventSource won't create log on install of service. RRS feed

  • Question

  • I know there are a couple different threads about this, but I have read these things all night and have yet to find a solution that works for me.  I have a service that I want to create a custom log for.  I have this in my project installer.cs file.

            string sLog = "AESLinkServiceLog";
            string sSource = "AESLinkService";
    
            public ProjectInstaller()
            {
                InitializeComponent();            
            }
            
                          
            public override void Install(IDictionary savedState)
            {
                base.Install(savedState);
                // Create the source, if it does not already exist.
                if (!System.Diagnostics.EventLog.SourceExists(sSource))
                {
                    System.Diagnostics.EventLog.CreateEventSource(sSource, sLog);
                }
            }
            
    
            public override void Uninstall(IDictionary savedState)
            {
    
                // Delete the source, if it exists.
                if (System.Diagnostics.EventLog.SourceExists(sSource))
                {
                    System.Diagnostics.EventLog.DeleteEventSource(sSource);
                    System.Diagnostics.EventLog.Delete(sLog);
                }
                base.Uninstall(savedState);
    
            }

    This fails to create the log everytime.  I have this code in the start of my service, but it does no good either.

    eventLog = new EventLog();
                if (!EventLog.SourceExists("AESLinkService"))
                    EventLog.CreateEventSource("AESLinkService", "AESLinkServiceLog");
                eventLog.Source = "AESLinkService";
                eventLog.Log = "AESLinkServiceLog";

    Any ideas on things to check or look at would be really appreciated.

    Wednesday, February 15, 2012 3:50 AM

Answers

  • If your event view application is not running as Administrator, you may want to check system32\config\<logname>.evt for the access right for that account.

    Event logs created when service installing, so if the service is automatically installed during installer run, it would mean the new event log only has right for TrustedInstaller, Administrators and SYSTEM accounts only.

    • Marked as answer by Paul Zhou Thursday, February 23, 2012 9:00 AM
    Thursday, February 16, 2012 2:21 AM
    Answerer

All replies

  • Read the lines under "Figure 2" here.
    Wednesday, February 15, 2012 7:32 AM
    Answerer
  • I swore my code was working and I was right.  I was using the event View app itself to look for the log.  It doesn't show up there for unknown reasons.  It does however show up in the Management console and is logging just fine.
    Wednesday, February 15, 2012 3:31 PM
  • If your event view application is not running as Administrator, you may want to check system32\config\<logname>.evt for the access right for that account.

    Event logs created when service installing, so if the service is automatically installed during installer run, it would mean the new event log only has right for TrustedInstaller, Administrators and SYSTEM accounts only.

    • Marked as answer by Paul Zhou Thursday, February 23, 2012 9:00 AM
    Thursday, February 16, 2012 2:21 AM
    Answerer