Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:05:01+00:00 2026-05-24T23:05:01+00:00

First time playing with Log4Net and I’m running into trouble. I’ve followed various tutorials

  • 0

First time playing with Log4Net and I’m running into trouble. I’ve followed various tutorials but I’ve been unable to get it to log anything out. Let me show you my code and hopefully you can tell me what I’m doing wrong.

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" 
             type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>  
  <log4net>    
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="CurrentLog.txt"/>
      <staticLogFileName value="true"/>
      <appendToFile value="true"/>
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd"/>
      <filter type="log4net.Filter.LevelRangeFilter">
        <acceptOnMatch value="true" />
        <levelMin value="DEBUG" />
        <levelMax value="FATAL" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{dd MMM yyy HH:mm:ss} %level %message. %newline %exception" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="RollingFileAppender" />
    </root>
  </log4net>
</configuration>

AssemblyInfo.cs

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

Presenter.cs

At the top of the class I have this:

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Then I try to use the log variable later in the class:

bool isDebugEnabled = log.IsDebugEnabled;
log.Debug("Failed to save", e);

Whenever I inspect the isDebugEnabled variable, it is false, as are all of the other isBlahEnabled if I inspect the log variable.

My suspicion is that I have not hooked up my app.config file correctly because this is the first time I have tried to use one. I created by right clicking on the project in solution explorer, adding a new item, choosing Application Configuration File and naming it app.config.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:05:02+00:00Added an answer on May 24, 2026 at 11:05 pm

    This one works for me:

    app.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        </configSections>
        <log4net>
          <appender name="Main" type="log4net.Appender.RollingFileAppender">
            <file value="${USERPROFILE}\My Documents\MyApp\Logs\Main.log" />
            <appendToFile value="false" />
            <maximumFileSize value="1GB" />
            <maxSizeRollBackups value="3" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%date{ABSOLUTE} %-5level %-18logger %message%newline" />
            </layout>
          </appender>
          <root>
            <level value="DEBUG" />
            <appender-ref ref="Main" />
          </root>
        </log4net>
    </configuration>
    

    Also be sure the build action on app.config is set to None and Copy to output dir is set to “Copy if newer”. You can set these settings in the file properties.

    Program.cs

    public static ILog Log;
    
    static void Main(string[] args)
    {
        // Setup Logging
        log4net.Config.XmlConfigurator.Configure();
        Log = LogManager.GetLogger("MyAwesomeApp");
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running Ubuntu and playing with Emacs for the first time but unfortunately it
I'm playing with rails for the first time and running into errors with gems.
I'm playing around with MVC2 for the first time and running into some caching
Playing with jquery for the first time, and I'm trying to get a simple
I'm playing around with GHCi for the first time, and I'm having some trouble
I'm playing with Python and Google App Engine for the first time but am
I've been playing around with WPF for the first time, specifically using a ListView
I have been playing with jstree (1.0rc2)+jquery (1.4.2) for the first time with c#.net
My first time playing around with JOGL, and I get this: Exception in thread
I have been playing with google charts for the first time. I have created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.