How do I disable log4net status messages to the console?

后端 未结 9 769
悲&欢浪女
悲&欢浪女 2021-01-11 16:44

I am using log4net in my .NET 3.5 console application and would like the log messages I generate to be seen in both the console standard out and the RollingFileAppender. The

相关标签:
9条回答
  • 2021-01-11 17:19

    In the app I inherited, there was the line:

    <appSettings>
       <add key="log4net.Internal.Debug" value="true"/>
    

    Changing that to false fixed the problem.

    0 讨论(0)
  • 2021-01-11 17:19

    please look at log4net faq. they realy have all those common pitfalls you might encounter.

    0 讨论(0)
  • 2021-01-11 17:20

    I just went through this same problem (which, unsurprisingly, is how I found this question).

    Anyway, my problem, and possibly yours as well, was caused by a web/app config file setting of "<log4net debug=true>". Too obvious, right? I had pasted the skeleton of my app.config settings in from a web snippet, and had focused on the appenders, not really giving the root log4net element a second glance. But there you have it. This is in the FAQ, but again other things caught my eye and not this attribute.

    0 讨论(0)
  • 2021-01-11 17:24

    If you have this in your code:

    log4net.Config.BasicConfigurator.Configure();
    

    Change it to:

    log4net.Config.XmlConfigurator.Configure();
    
    0 讨论(0)
  • 2021-01-11 17:29

    Please try to replicate the problem using a new project one step at the time (first reference log4net with no appender, then with the console appender, then with both appenders). If it shows the same behavior, please post the complete config of log4net.

    Also you could try using the configuration samples from log4net Config Examples page.

    Edit: This could be the cause of those messages: How do I enable log4net internal debugging.

    0 讨论(0)
  • 2021-01-11 17:30

    set debug = false

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
      </configSections>
    
      <log4net debug="false">
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="your file name" />
          <appendToFile value="true" />
          <rollingStyle value="Size" />
          <maxSizeRollBackups value="10" />
          <maximumFileSize value="10MB" />
          <staticLogFileName value="true" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
          </layout>
        </appender>
    
        <root>
          <level value="DEBUG" />
          <appender-ref ref="RollingLogFileAppender" />
        </root>
      </log4net>
    </configuration>
    
    0 讨论(0)
提交回复
热议问题