以下是我的web.config信息:

  <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      <log4net>
        <root>
                <level value="ALL" />
        </root>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
              <file value="c:\temp\log-file.txt" />
              <appendToFile value="true" />
              <rollingStyle value="Size" />
              <maxSizeRollBackups value="10" />
              <maximumFileSize value="1MB" />
              <staticLogFileName value="true" />
              <layout type="log4net.Layout.SimpleLayout" />
        </appender>
      </log4net>
...

下面是初始化记录器的代码:
protected void SendMessage()
    {
        log4net.Config.XmlConfigurator.Configure();
        ILog log = LogManager.GetLogger(typeof(Contact));
        ...
        log.Info("here we go!");
        log.Debug("debug afasf");
        ...
     }

不管我看起来怎么做,都没用。我正确地引用了“Log4NET.DLL”,并且通过调试应用程序,我可以看到日志对象被正确地启动。这是一个asp.net 3.5framework web项目。有什么想法/建议吗?
我原以为这个错误可能是由于文件写入权限限制,但事实似乎并非如此(或者我是这么认为的)。

最佳答案

我找到了答案:我需要web.config配置文件中的requireMission=“false”标记。

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" **requirePermission="false"**/>
</configSections>

关于c# - 非常简单的文件追加程序日志记录不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2850380/

10-11 12:38
查看更多