log4net配置错误 - 无法找到app.config

时间:2014-06-29 16:56:23

标签: winforms log4net log4net-configuration

我正在尝试在帮助程序项目(AC.Helpers)中实现log4net,当它运行配置时,我在“输出”窗口中收到以下错误 -

  

log4net:ERROR无法在应用程序的.config文件中找到配置节'log4net'。检查.config文件中的和元素。配置部分应如下所示:

LoggerBase.cs -

public abstract class LoggerBase
{
    #region Member Variables

    /// <summary>
    /// Member variable to hold the <see cref="ILog"/> instance.
    /// </summary>
    private readonly log4net.ILog logger = null;

    #endregion

    #region Properties

    /// <summary>
    /// Abstract property which must be overridden by the derived classes.
    /// The logger prefix is used to create the logger instance.
    /// </summary>
    protected abstract System.Type LogPrefix
    {
        get;
    }

    #endregion

    #region Constructors

    private static bool isConfigured = false;
    /// <summary>
    /// Constructor of the class.
    /// </summary>
    public LoggerBase()
    {
        // initiate logging class           
        if (!isConfigured)
        {
            log4net.Config.XmlConfigurator.Configure();
            isConfigured = true;
        }
        logger = log4net.LogManager.GetLogger(this.LogPrefix);
    }

    #endregion

App.config -

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

  <log4net>
    <appender name="Console" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level: %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="INFO" />
      <appender-ref ref="Console" />
    </root>
  </log4net>
</configuration>

为什么我得到这个?其他帖子建议将log4net配置移动到自己的文件中,并在AssemblyInfo.cs中使用以下内容(尝试过,但没有成功)

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

0 个答案:

没有答案