log4net使用时没有日志输出信息
配置文件如下,程序中Globals.sLog = LogManager.GetLogger("GUILogger");但是sLog的IsDebugEnabled等属性均为false.不知什么原因
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender" Additivity="true">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value=".yyyyMMdd" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="4MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<ConversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fff} %5level [%4thread] %-20logger - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
</appender>
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender" Additivity="true">
<mapping>
<level value="FATAL" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="ERROR" />
<foreColor value="Red" />
</mapping>
<mapping>
<level value="WARN" />
<foreColor value="Yellow, HighIntensity" />
</mapping>
<mapping>
<level value="INFO" />
<foreColor value="White, HighIntensity" />
</mapping>
<mapping>
<level value="DEBUG" />
<foreColor value="Green, HighIntensity" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<ConversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fff} %5level [%4thread] %-10logger - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
</appender>
<logger name ="Coordiantor">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</logger>
<logger name ="GUILogger">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</logger>
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</root>
</log4net>
</configuration>
[解决办法]
要读取配置文件,winform下在项目的AssemblyInfo.cs中:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = ".\\log4net.config", Watch = true)]