Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure log4net so that log.IsDebugEnabled is true?

I am trying to use log4net in an ASP.NET application with Visual Studio 2005. I have declared an instance of the logger like so:

Private Shared ReadOnly log As ILog = LogManager.GetLogger("") 

I am trying to use it in the following manner:

If log.IsDebugEnabled Then    log.Debug("Integration Services Constructed") End If 

Here is my configuration:

<log4net>      <root>         <level value="DEBUG" />         <appender-ref ref="RollingFileAppender" />     </root>      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">         <file value="..\\logs\\logfile.log"/>         <appendToFile value="true"/>         <rollingStyle value="Size"/>         <maxSizeRollBackups value="10"/>         <maximumFileSize value="1MB"/>         <staticLogFileName value="true"/>         <layout type="log4net.Layout.PatternLayout">             <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>         </layout>         <filter type="log4net.Filter.LevelRangeFilter">             <param name="LevelMin" value="DEBUG" />             <param name="LevelMax" value="FATAL" />         </filter>     </appender>  </log4net> 

Unfortunately, log.IsDebugEnabled is always false.
How do I configure log4net so that I can log only debug messages?

like image 731
Ryan Taylor Avatar asked Oct 20 '08 21:10

Ryan Taylor


People also ask

Is log4net dependent on log4j?

log4net is a port of the popular Apache log4j™ logging library. The initial port was done in June 2001, since then we have tried to remain in the spirit of the original log4j. See the log4net history page for more details.

What is log4net config?

The log4net configuration can be configured using assembly-level attributes rather than specified programmatically. If specified, this is the filename of the configuration file to use with the XmlConfigurator. This file path is relative to the application base directory (AppDomain. CurrentDomain.


1 Answers

Before calling LogManager.GetLogger("")

You have to call log4net.Config.XmlConfigurator.Configure(); In an ASP.NET app you probably want to put this call in Application_Start

like image 104
Anson Smith Avatar answered Sep 23 '22 02:09

Anson Smith