title: How to debug FileSystemWatcher c#
body: <p>Can someone explain how I debug this?</p>
  
  <p>I have built a windows service which monitors a folder and when a file is created in that folder, it moves that newly created file to another folder. Pretty simple and works. I am trying to pad it out now with out features and I'm starting to get generic IOExpections thrown in event viewer, so I want to try and debug. But the issue I am having is when to create the new file in the directory during debugging.</p>
  
  <p>This is my code so far</p>
  
  <p>which line should I stop at during stepping through, place my new file in the directory and then continue debugging so that it picks up the created file?</p>
  
  <pre><code>public void OnDebug()
      {
          OnStart(null);
      }
  
      [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
      protected override void OnStart(string[] args)
      {
          string pathToWatch = ConfigurationManager.AppSettings["DirectoryToWatch"];
  
          FileSystemWatcher watcher = new FileSystemWatcher();
          watcher.Path = pathToWatch;
          watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName;
          watcher.Created += new FileSystemEventHandler(FileCreated);
          watcher.EnableRaisingEvents = true;
      }
  
      private void FileCreated(object source, FileSystemEventArgs e)
      {
          try
          {
              DateTime dt = File.GetCreationTime(e.FullPath);
              File.Move(e.FullPath.ToString(), ConfigurationManager.AppSettings["DirectoryToMoveTo"] + e.Name + dt.ToString());
              LogEvent($"New file found and moved \n {e.FullPath.ToString()}");
          }
          catch (IOException ex)
          {
              LogEvent(ex.ToString());
          }           
      }
  </code></pre>