title: Windows Service not working when installed, works fine in Debug mode; crashes on Moving/deleting files
body: <p>I created a windows service which watches a directory. When a file is dumped into it, it takes the data and puts it into a database. Then this file is moved to another directory and deleted. It works fine in debug mode. But when i install it on my computer it stops after throwing the data into the database and the file in question is neither moved or deleted. I suspect a permission issue is involved. I tried to create a event log:</p>
  
  <pre><code>public Service1()
      {
          InitializeComponent();
          if (!System.Diagnostics.EventLog.SourceExists("MySource"))
          {
              System.Diagnostics.EventLog.CreateEventSource(
                  "MySource", "MyNewLog");
          }
          eventLog1.Source = "MySource";
          eventLog1.Log = "MyNewLog";         
      }
  </code></pre>
  
  <p>So i have three questions. 
  (1) What could be causing my service to work as described in debug but fail when installed on my computer.(2) I have initiated a event log as shown above. But do i need to add other code to record the event of my service stopping. I presume this would be done in a 'override onShutdown' method.(3) Finally when my service stops, i want to look at the event log. But i do not know how to do this, is in administrative tools? stored as a file on some directory?</p>
  
  <p>Here is edit to this post in lieu of the grateful advice given below.</p>
  
  <pre><code>      try
          {
              File.Move(e.FullPath, finalString);
              File.Delete(e.FullPath);
          }
          catch(Exception q)
          {
              EventLog.WriteEntry("MySource", q.ToString(), EventLogEntryType.Error);
  
              using (StreamWriter w = new StreamWriter(ConfigurationManager.AppSettings["fmd"], true))
              {
                  w.Write(DateTime.Now.ToString("dd-MM-yyyy_hh-mm-ss"));
                  w.Write(q.ToString());
              }
          }
  </code></pre>
  
  <p>As per suggestion i put a try-catch around the file move and delete plus i added a OnShutdown method:</p>
  
  <pre><code> protected override void OnShutdown()
      {
          using (StreamWriter w = new StreamWriter(ConfigurationManager.AppSettings["ond"], true))
          {
              w.Write("stop OnShutdown");
          }
          //EventLog.WriteEntry("MySource", message, EventLogEntryType.Error);
      }
  </code></pre>
  
  <p>I do not know how to pass any system error message to the shutdown method, so any advice appreciated. When i installed my modified code as a service, it again stopped before moving or deleting the files. Neither of my two logs accessed by a stream recorded anything. Plus the event viewer showed nothing either?  </p>