title: Steps to configure log4net in a C# service application
body: <p>I am extremely confused about how to configure log4net in a Windows Service project.  Add to that, that I'm a newbie with Visual Studio configurations.  So, I've created this Windows Service application and I want to add log4net to it.  All instructions are different and one answer said to include the following line to the assembly info.  Another answer said to add it to the AssemblyInfo.cs (in your App_Code folder).  So does this mean that I need to add a class called AssemblyInfo.cs in my sources folder and then just add this line in the constructor?  <strong>I don't know what that means!</strong></p>
  
  <pre><code>[assembly:log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
  </code></pre>
  
  <p>I've added the appSettings to my app.config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
      &lt;appSettings&gt;
          &lt;add key="log4net.Internal.Debug" value="true"/&gt;
      &lt;/appSettings&gt; 
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>Do I also need to create a log4net.config file?</strong></p>
  
  <p>I tried to follow instructions from <a href="https://stackoverflow.com/q/1605765/1735836">this questions</a> but there's just not enough information to make sense to me.  I've spent hours looking for instructions that make sense.  Can someone please tell me (<strong>at a high level</strong>) the steps to configure log4net for a Windows Service application?  Which files I need to create; what configurations I need to add; I know I will need to create a logger class but the configuration has me completely confused.</p>
  
  <p><strong>---------------------------------EDIT----------------------------------</strong></p>
  
  <p><strong>Step 1)</strong>  My app.config looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
  
      &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;file value="log.log" /&gt;
          &lt;appendToFile value="true" /&gt;
          &lt;rollingStyle value="Size" /&gt;
          &lt;maxSizeRollBackups value="5" /&gt;
          &lt;maximumFileSize value="100KB" /&gt;
          &lt;staticLogFileName value="true" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%date %level %logger - %message %exception%newline" /&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;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>Step 2)</strong>  I've added this the Program.cs main:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.ServiceProcess;
  using System.Text;
  using System.Threading.Tasks;
  
  [assembly: log4net.Config.XmlConfigurator(Watch = true)]
  
  namespace MyAppService
  {
      static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          static void Main()
          {
              log4net.Config.XmlConfigurator.Configure();
  </code></pre>
  
  <p><strong>Step 3)</strong>  I've added the reference to log4net</p>
  
  <p><strong>Step 4)</strong>  In my classes where I am logging I've added this:</p>
  
  <pre><code>private static ILog logger = LogManager.GetLogger(typeof(Reader));
  </code></pre>
  
  <p><strong>Step 4)</strong>  I've added logging statements like this:</p>
  
  <pre><code>logger.Info("Data Read Completed Successfully.");
  </code></pre>