You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Steve Gross <St...@verificationsinc.com> on 2011/10/13 18:29:47 UTC

How to verify my App.config file is being read?

Hi folks. I'm using TFS 2010, and am trying to get log4net working.
Here's what I've done:

1. Created an App.config file with contents like so:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <appSettings>
    <add key="config.type" value="unit.test"/>
  </appSettings>
  <log4net>
    <appender name="NUnitFileAppender"
type="log4net.Appender.FileAppender">
    ...
    </appender>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="NUnitFileAppender" />
      <appender-ref ref="NUnitConsoleAppender" />
    </root>
  </log4net>  
</configuration>

2. Verified that the file I created is being loaded in like so:

  Assert.AreEqual("unit.test",
System.Configuration.ConfigurationManager.AppSettings["config.type"]);

3. However, it looks like no appenders are actually loaded! When I run:

  IAppender[] appenders = LogManager.GetRepository().GetAppenders();
  System.Console.WriteLine("count of appenders: " + appenders.Count());

The system reports 0 appenders. Any ideas?

Thanks,
--Steve

Stephen Gross
QA Consultant
The New Guy

CONFIDENTIALITY NOTICE: Privileged or confidential information may be contained in this email transmission (and any attachments accompanying it). The information is intended only for the use of the intended recipient named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this emailed information, except its direct delivery to the intended recipient named above, is strictly prohibited. If you have received this email in error, please notify us immediately.


Re: How to verify my App.config file is being read?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-10-13, Steve Gross wrote:

> 1. Created an App.config file with contents like so:

> 2. Verified that the file I created is being loaded in like so:

> 3. However, it looks like no appenders are actually loaded! When I run:

This is to be expected.  The config section alone is not enough to
configure log4net, you still need to manually invoke Configure().

See the second paragraph in
<http://logging.apache.org/log4net/release/manual/configuration.html#dot-config>

Stefan