首页 > 解决方案 > log4net 在类库中不起作用

问题描述

I want to implement logging function into a class library, which is itself referenced in a webapplication. I tried to add app.config and did everything needed, but its not logging any message, log4net simply does nothing.
Here is my app.config


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

      <log4net debug="true">
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="D:\StagingPortal2012\Communicationlogs\TestProjlog4net.txt" />
          <appendToFile value="true" />
          <rollingStyle value="Size" />
          <maxSizeRollBackups value="10" />
          <maximumFileSize value="20MB" />
          <staticLogFileName value="true" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%newline%-5p %d %-22.22c{1} %-18.18M - %m%n" />
          </layout>
        </appender>

        <root>
          <appender-ref ref="RollingLogFileAppender" />
          <level value="DEBUG"></level>
        </root>
      </log4net>
      <appSettings>
        <add key="log4net.Internal.Debug" value="true" />
      </appSettings>

    </configuration>


And Assembly.Info.cs



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

还有 Communicator.cs(我用 log4net 写日志的地方)

私有静态只读 ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

标签: asp.net

解决方案


推荐阅读