title: Log4net and windows service. What else should I do to make this work
body: <p>Please help me, I want to run log4net on my windows service. And it is simply - mission impossible. </p>
  
  <p>First of all, with Win forms - work great. </p>
  
  <p>Here is what I do with windows service:</p>
  
  <p>Add to assembly:</p>
  
  <pre><code>[assembly: log4net.Config.XmlConfigurator(Watch = true)]
  </code></pre>
  
  <p>My config: </p>
  
  <pre><code>  &lt;configSections&gt;
      &lt;section name="log4net"
         type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /&gt;
    &lt;/configSections&gt;
  
    &lt;log4net&gt;
      &lt;appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
        &lt;param name="File" value="log-file.txt" /&gt;
        &lt;param name="AppendToFile" value="true" /&gt;
        &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;param name="ConversionPattern" value="%d [%t] %-5p %c: %m%n" /&gt;
        &lt;/layout&gt;
      &lt;/appender&gt;
      &lt;root&gt;
        &lt;level value="ALL" /&gt;
        &lt;appender-ref ref="LogFileAppender" /&gt;
      &lt;/root&gt;
    &lt;/log4net&gt;
  </code></pre>
  
  <p>My class: </p>
  
  <pre><code>public class LogProvider
  {
      private ILog _Log;
  
  
      public LogProvider(string className)
      {
          XmlConfigurator.Configure();
          _Log = LogManager.GetLogger(className);
      }
  
      public void Info(object message)
      {
          _Log.Info(message);
      }
  }
  </code></pre>
  
  <p>And in main program: </p>
  
  <pre><code>using log4net;
  using log4net.Config;
  
  (...)
  
  private LogProvider _logProvider;
  
  (...)
  
                  _logProvider = new LogProvider("Test");
                  _logProvider.Info("asds");
  </code></pre>
  
  <p>WHAT IS GOING ON ? </p>
  
  <p>If it possible, please show me sample project - because, this code above is about 100 version or more. I start to believe that this is impossible to use log4net using windows service. </p>
  
  <hr>
  
  <p>UPDATE: </p>
  
  <p>So, about permissions: 
  Actually I get an exception, about permissions. I fix this with this line (requirePermission="false"): </p>
  
  <pre><code>&lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/&gt;
  </code></pre>
  
  <p>Now, It still not working, with no exception. </p>
  
  <p>This is my final exec code: </p>
  
  <pre><code>protected override void OnStart(string[] args)
  {
      try
      {
  
          LogProvider lp = new LogProvider("asd");
          lp.Info("asd2");
      }
      catch (Exception ex)
      {
           System.IO.FileInfo _file;
           System.IO.StreamWriter _writer;
           _file = new System.IO.FileInfo("D:\\Log\\asdCatch.txt");
           _writer = _file.CreateText();
           _writer.WriteLine("[" + DateTime.Now.ToString() + "] Init Log");
           _writer.WriteLine("[" + DateTime.Now.ToString() + "] " + ex.ToString());
           _writer.Close();
  
      }
  }
  </code></pre>
  
  <p>Now I'm really confused, I've created another windows service and it's working - without that line with permission. OMG, this is weird. </p>
  
  <hr>
  
  <p>UPDATE2:
  OK, I've got it. I don't know how did this happened, but I found that line in my app.config: </p>
  
  <pre><code>  &lt;runtime&gt;
      &lt;NetFx40_LegacySecurityPolicy enabled="true"/&gt;
    &lt;/runtime&gt;
  </code></pre>
  
  <p>I'm working on 15-subproject program and seriously, I don't know where it came from:/ </p>