title: Using App.Config from Command Line for C# Programs
body: <p>I am learning log4net and currently testing out how to use App.Config for XMLConfiguration. </p>
  
  <p>The problem is that I do not have a .NET IDE such as Visual Studio 2008 or Express Edition at office (don't get me started on why/how :-))</p>
  
  <p>I need to compile and run my code where log4net reads the configuration settings from App.Config. How do I do it?</p>
  
  <p>My C# code is as follows. </p>
  
  <pre><code>public class BasicXMLConfiguration
  {
      public static void Main (string [] args)
      {
          log4net.Config.XmlConfigurator.Configure();
          log4net.ILog log = 
                       log4net.LogManager.GetLogger(typeof(BasicXMLConfiguration));
          log.Info("beginning of loop");
          for (int c = 0; c &lt; 10; c++)
          {
              log.DebugFormat("Loop Count is {0}", c);
          }
          log.Info("looping ends");
      }
  }
  </code></pre>
  
  <p>My App.Config is as follows</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
  
      &lt;configSections&gt;
          &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/&gt;
      &lt;/configSections&gt;
  
      &lt;log4net&gt;
  
          &lt;!--
          &lt;appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"&gt;
              &lt;layout type="log4net.Layout.SimpleLayout" /&gt;
          &lt;/appender&gt;
          --&gt;
          &lt;!-- Never, ever use the FileAppender. Instead, use the RollingFileAppender --&gt;
          &lt;!--
          &lt;appender name="FileAppender" type="log4net.Appender.FileAppender"&gt;
              &lt;file value="C:\My_Code\Log4NetTutorials\Log_Files\log-file.txt" /&gt;
              &lt;appendToFile value="true" /&gt;
              &lt;encoding value="utf-8"/&gt;
              &lt;layout type="log4net.Layout.SimpleLayout" /&gt;
          &lt;/appender&gt;
          --&gt;
          &lt;appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
              &lt;file value="C:\My_Code\Log4NetTutorials\Log_Files\log-file.txt" /&gt;
              &lt;appendToFile value="true" /&gt;
              &lt;rollingStyle value="Size" /&gt;
              &lt;maxSizeRollBackups value="10" /&gt;
              &lt;maximumFileSize value="10MB" /&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>My command that I use is this</p>
  
  <pre><code>csc BasicXMLConfiguration.cs /r:log4net.dll
  </code></pre>
  
  <p>It compiles fine. However, when I run the exe as</p>
  
  <pre><code>BasicXMLConfiguration.exe
  </code></pre>
  
  <p>I get the following error. </p>
  
  <pre><code> log4net:ERROR XmlConfigurator: Failed
   to find configuration section 'log4net' in  the application's
   .config file. Check your .config file for the &lt;log4net&gt; and &lt;
   configSections&gt; elements. The configuration section should look
   like: &lt;section n ame="log4net" 
        type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/&gt;
  </code></pre>
  
  <p>How do I make it to reference the App.Config?</p>