title: Log4net with a Windows Service
body: <p>I'm trying to get log4net working for a Windows service. It works fine for a console application.</p>
  
  <p>I've created a blank service and the only thing it should do is write out a log statement to a file.</p>
  
  <p>This is my main method.</p>
  
  <pre class="lang-cs prettyprint-override"><code>log4net.Config.XmlConfigurator.Configure();
  log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  
  log.Info("Test");
  
  ServiceBase[] ServicesToRun;
  ServicesToRun = new ServiceBase[]
  {
      new Service1() 
  };
  ServiceBase.Run(ServicesToRun);
  </code></pre>
  
  <p>This is my app.config file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/&gt;
  &lt;/configSections&gt;
  
  &lt;log4net&gt;
    &lt;appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
      &lt;file value="Test.log" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;rollingStyle value="Size" /&gt;
      &lt;maxSizeRollBackups value="10" /&gt;
      &lt;maximumFileSize value="1MB" /&gt;
      &lt;staticLogFileName value="true" /&gt;
      &lt;layout type="log4net.Layout.SimpleLayout" /&gt;
    &lt;/appender&gt;
  
    &lt;root&gt;
      &lt;level value="ALL" /&gt;
      &lt;appender-ref ref="RollingFileAppender" /&gt;
    &lt;/root&gt;
  &lt;/log4net&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I've also added this line to my AssemblyInfo.cs file:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[assembly: log4net.Config.XmlConfigurator(Watch = true)]
  </code></pre>
  
  <p>According to everything I've read online, this should be enough to create the log file in the directory where the service installed from. When this didn't happen, I tried putting absolute directories as</p>
  
  <pre class="lang-cs prettyprint-override"><code>log4net.Config.XmlConfigurator.Configure(new FileInfo("C:\\Users\\Public\\app.config"));
  </code></pre>
  
  <p>and</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;file value="C:\Users\Public\Test.log" /&gt;
  </code></pre>
  
  <p>This didn't work either. I thought maybe it was some crazy permissions problem since the service runs under a potentially restricted account, but I've just tried running it as an administrator and the file still isn't created.</p>
  
  <p>What am I doing wrong here?</p>