title: Don't want to use Registry in Windows Service
body: <p>I want to remove registry dependency in my Windows service written in C#. and want to maintain Event Logs under Event Viewer under application.
  I am using the below code which does not seem correct as I do not want to use Registry.</p>
  
  <p>I am getting Source property was not set before writing to the event log.</p>
  
  <p>Please advice.</p>
  
  <pre><code>public Service()
  {           
      try
      {
          InitializeComponent();
          if(!System.Diagnostics.EventLog.SourceExists("VWinService"))
              System.Diagnostics.EventLog.CreateEventSource("VWinService","");
          eventLog1.Source = "VWinService";
          eventLog1.Log = "";     
  
      }
      catch (Exception ex)
      {               
          eventLog1.WriteEntry("Error in Service Constructor.  Error message = " + ex.Message.ToString(), EventLogEntryType.Error);
      }
  } 
  
  
   private void InitializeComponent()
      {       
          this.eventLog1 = new System.Diagnostics.EventLog();
          this.tmrSend = new System.Timers.Timer();
          ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
          ((System.ComponentModel.ISupportInitialize)(this.tmrSend)).BeginInit();
          this.tmrSend.Elapsed += new System.Timers.ElapsedEventHandler(this.tmrSend_Elapsed);
          this.AutoLog = false;
          this.ServiceName = "VWinService";
          ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
          ((System.ComponentModel.ISupportInitialize)(this.tmrSend)).EndInit();
      }
  </code></pre>