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 1004561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:09:13+00:00 2026-05-16T08:09:13+00:00

I have a class namespace LogToolsTest { public class Foo { private static readonly

  • 0

I have a class

namespace LogToolsTest
{
    public class Foo
    {
        private static readonly ILog logger = LogManager.GetLogger(typeof(Foo));

        public Foo()
        {

            logger.Debug("Save this text");
            logger.Info("Save this text");
            logger.Warn("Save this text");
            logger.Error("Save this text");
            logger.Fatal("Save this text");


            var b1 = logger.IsDebugEnabled;
            var b2 = logger.IsInfoEnabled;
            var b3 = logger.IsWarnEnabled;
            var b4 = logger.IsErrorEnabled;
            var b5 = logger.IsFatalEnabled;
        }
    }
}

I test this by simple:

 Foo foo = new Foo();

and log4net.config

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="EventLogAppender" />
  </root>

  <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>


</log4net>

I added to my assemblyinfo:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = 
"App.config", Watch = true)]

After execution of this code there is no entry in the event log. Why is that?

Now it’s working almost ok:
I deleted log4net.config, and modified my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <log4net>
  <root>
    <priority value="ALL" />
    <appender-ref ref="TraceAppender" />
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="FileAppender" />
    <appender-ref ref="EventLogAppender" />
  </root>

  <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>

  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>

  <appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file value="c:\\LOGS\\SampleLog.txt" />
    <appendToFile value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>
  <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
    <layout type="log4net.Layout.PatternLayout">
    </layout>
  </appender>
</log4net>
<configSections>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>

</configuration>

But something is wrong. I see in output:

System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section log4net. (C:\toolkit\trunk\LogToolsTest\bin\Debug\LogToolsTest.vshost.exe.config line 3)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
   at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
   at System.Diagnostics.DiagnosticsConfiguration.Initialize()
   at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
   at System.Diagnostics.TraceInternal.InitializeSettings()
   at System.Diagnostics.TraceInternal.WriteLine(String message)
   at System.Diagnostics.Trace.WriteLine(String message)
   at log4net.Util.LogLog.EmitErrorLine(String message)
log4net:ERROR DefaultRepositorySelector: Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section log4net. (C:\toolkit\trunk\LogToolsTest\bin\Debug\LogToolsTest.vshost.exe.config line 3)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at log4net.Util.SystemInfo.GetAppSetting(String key)

foreach appender.

  • 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-16T08:09:14+00:00Added an answer on May 16, 2026 at 8:09 am

    I assume that you have a console program (it looks like you are testing log4net). So the first thing I would do is to make sure that logging works with more basic appenders. Configure a ConsoleAppender and make sure that you see the log statements. It is not strictly necessary to this, but as I said, that is what I would do.

    The more important thing to do is to turn on internal debugging that should tell you why nothing is written to the event log.

    Most likely you are facing a permission problem. Cf. log4net faq.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 503k
  • Answers 503k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer use strict; use warnings; my $string = "COMPANY NAME City… May 16, 2026 at 2:57 pm
  • Editorial Team
    Editorial Team added an answer You don't need to escape the " inside '. $bbreplacements… May 16, 2026 at 2:57 pm
  • Editorial Team
    Editorial Team added an answer The reason why is that what's actually happening here is… May 16, 2026 at 2:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Imagine I have this class namespace CommonLibrary { public class Report() { public DateTime
I have a class named SimObject: namespace simBase { class __declspec(dllexport) SimObject: public SimSomething
If you have a namespace that contains a property in ClassA and a class
I have a strange problem in my project. I have a class that inherits
I have a custom class Contact . I am trying to bind a List<Contact>
If you have a class that has some named constants, what is the best
I have a class encapsulating a bunch of collections. I would like to bind
I have a system with 2 different projects, one is called LINQ_Extensions and the
I am trying to share a common namespace between two projects in a single
This situation probably is not entirely uncommon to some of you: you have some

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.