title: Windows service Started and stopped automatically, exception handling issue
body: <p>I have developed a 32 bit service, I am running it in Windows 7 Home Premium x64.
  Problem is when I start it, windows gives me the following message </p>
  
  <blockquote>
    <p>The WLConsumer service on Local Computer started and then stopped. Some services stop 
    automatically if they are not in use by other services or programs.</p>
  </blockquote>
  
  <p>I found the following message in the event log</p>
  
  <blockquote>
    <p>Service cannot be started. System.ArgumentException: Log WLConsumer has already been registered as a source on the local computer.
       at System.Diagnostics.EventLogInternal.CreateEventSource(EventSourceCreationData sourceData)
       at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
       at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
       at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)
       at WeblogicConsumerService.WeblogicConsumer.winEventlogMe(String logTxt, String logSrc, Char entryType) in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 136
       at WeblogicConsumerService.WeblogicConsumer.OnStart(String[] args) in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 63
       at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)</p>
  </blockquote>
  
  <p>This is my codeblock in the OnStart() method</p>
  
  <pre><code>   protected override void OnStart(string[] args)
      {
          #region WEBLOGIC CREDENTIALS
          try
          {
              //Weblogic URL
              this.url = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("URL").ToString();
  
              //Queue name
              this.qName = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("Queue").ToString();
  
              //Weblogic login name
              this.user = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("User").ToString();
  
              //Weblogic password
              this.pwd = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("Pwd").ToString();
  
              //Weblogic Connection Factory
              this.cfName = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("ConnectionFactory").ToString();
  
              //root folder
              this.rFolder = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("root").ToString();
          }
          catch (Exception e)
          {
              winEventlogMe(e.Message, "WLRegistryKeys", 'e');
          }
          #endregion
  
          winEventlogMe("Successful start", "SeriviceStartup", 'i');
          synchro.Enabled = true;
      }
  </code></pre>
  
  <p>winEventLogMe is the method I am calling for logging.</p>
  
  <pre><code>        public static void winEventlogMe(string logTxt, string logSrc, char entryType)
      {
          #region Log
          //Log to event log
  
          EventLog theEvent = new EventLog("WLConsumer");
          theEvent.Source = logSrc;
          if (entryType == 'e')
              theEvent.WriteEntry(logTxt, EventLogEntryType.Error);
          else if (entryType == 'i')
              theEvent.WriteEntry(logTxt, EventLogEntryType.Information);
          else if (entryType == 'w')
              theEvent.WriteEntry(logTxt, EventLogEntryType.Warning);
          else
              theEvent.WriteEntry(logTxt, EventLogEntryType.Error);*/
          #endregion
      }
  </code></pre>
  
  <p>When I comment out the calls to winEventLogMe() method in the OnStart() method, the service starts without an error. So obviously something is wrong with the winEventLogMe() method.
  Can someone please help me figure out whats the problem as I am totally clueless on how to solve this issue now.</p>
  
  <p>thanx in advance :)</p>
  
  <hr>
  
  <p>@nick_w I have edited my code as you suggested, the service started succesfully. But on Stopping it I got the following message:</p>
  
  <blockquote>
    <p>Failed to stop service. System.ArgumentException: The source 'WLConsumer2012' is not registered in log 'ServiceStop'. (It is registered in log 'SeriviceStartup'.) " The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property.
       at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
       at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
       at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)
       at WeblogicConsumerService.WeblogicConsumer.winEventlogMe(String logTxt, String logSrc, Char entryType) in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 139
       at WeblogicConsumerService.WeblogicConsumer.OnStop() in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 70
       at System.ServiceProcess.ServiceBase.DeferredStop()</p>
  </blockquote>
  
  <p>here is the OnStop() method</p>
  
  <pre><code>        protected override void OnStop()
      {
          winEventlogMe("Successful stop", "ServiceStop", 'i');
      }
  </code></pre>
  
  <p>These event logs are starting to confuse me a lot. I have done the same method of logging in other services and never encountered such problems. How can I be getting these errors in this service yet its not much different from all the others I have done :(</p>