Log4Net log is displayed in the console window

I have the opposite problem, like most people with Log4net. I have a basic downloadable list of logs, I use the INFO, WARN and ERROR levels in my code. I have disabled debugging in app.config. It STILL pushes log data into the console window in addition to a sliding log application.

How to stop this behavior? This makes looking at the console window a nightmare.

My configuration:

<log4net debug="false"> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <file type="log4net.Util.PatternString" value="milliondollars.log"/> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <rollingStyle value="Composite"/> <filter type="log4net.Filter.LevelRangeFilter"> <acceptOnMatch value="true" /> <levelMin value="INFO" /> <levelMax value="FATAL" /> </filter> <datePattern value="yyyyMMdd"/> <maxSizeRollBackups value="100"/> <maximumFileSize value="15MB"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date %-5level %logger: %message%newline" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="RollingFileAppender" /> </root> </log4net> 
+4
source share
3 answers

Based on the additional information you provided, there are several things that I see. First, you log all messages (including DEBUG messages). You simply do not show log4net debugging information. As for why you are writing in the console window, I would suggest looking at the wrapper for your journal messages. Perhaps you write to the console there.

Also go through running your program in debug mode. See which line is written to the console.

+1
source

Well, it looks like you no longer want to give up the details ...

I can think of possible reasons:

  • You have a console appender specified in any <logger> or <root> section
  • You programmatically register a console appender
  • You have a log wrapper that always runs the Console.Write line before logging
+1
source

My problem was to use this when creating the registrar instance;

  log4net.Config.BasicConfigurator.Configure(); ILog log = log4net.LogManager.GetLogger(typeof(Program)); 

I took me a little to understand this ignored my default configuration and initialization. Replaced it with what people offer, and it works great;

  private static readonly log4net.ILog log = log4net.LogManager.GetLogger (System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 

Source: http://elegantcode.com/2007/12/07/getting-started-with-log4net/

0
source

All Articles