开发者

log4net is logging all levels, instead of what I've configured it to do

I have the level set to "INFO" but I'm seeing DEBUG events in the log.

Config

<?xml version="1.0"?>

<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    </configSections>

    <log4net>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <level value="INFO"/>
            <file value="Logs\Log.txt" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="10" />
            <开发者_运维知识库;maximumFileSize value="10MB" />
            <staticLogFileName value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
            </layout>
        </appender>

        <root>
            <appender-ref ref="RollingFileAppender"/>
        </root>
    </log4net>
</configuration>

Code

private ILog Log { get; set; }

static Program()
{
    XmlConfigurator.Configure();
    //...
    this.Log.Info("Started in RunOnce mode.");
}


I think that within your root tag you need to set the property <level value="INFO"> for your appender.


have a look at

http://logging.apache.org/log4net/release/sdk/log4net.Core.Level.html

It looks like this could be the cuplrit

When logging at level INFO the actual level used is not Info but the value of LoggerRepository.LevelMap["INFO"]. The default value for this is Info, but this can be changed by reconfiguring the level map


I typically declare/initialize my ILog with:

private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

and then define the logger in the web config: (include full namespace of Program)

<logger name="Program">
  <level value="Info"/>
  <appender-ref ref="RollingFileAppender"/>
</logger>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜