log4net problem under my solution
Under my VS2010 solution I've this situation:
- WEBSITE
- Library1
- Library2
On global.asax.cs I initialize the log4net configuration using:
private static log4net.ILog _logger = log4net.LogManager.GetLogger("globalASAX");
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
log4net.Config.XmlConfigurator.Configure();
_logger.Info("[APPLICATION START] " + DateTime.Now.ToString());
}
It works fine and Application start message is correclty available on log.txt file. The problem happens when I try to use log something on the classes available on DLL Library1 or Library2.
I added the row:
private static log4net.ILog _logger = log4net.LogManager.GetLogger(typeof(ImageRepository));
but when I try to all the _logger.error("blabla") nothing happens on log file; all properties of _logger are false (i.e. isdebugenable=false). How can I fix开发者_Go百科 that? I followed the instruction available here:
http://logging.apache.org/log4net/release/manual/configuration.html
the configuration of log4net is under web.config file:
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString">
<conversionPattern value="log\explorer-log-%date{ yyyy.MM.dd.HH.mm.ss}-[%processid].log"/>
</file>
<appendToFile value="true"/>
<maximumFileSize value="1024KB"/>
<maxSizeRollBackups value="5"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger - %message%newline"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingFile"/>
</root>
</log4net>
anyone can help me? thanks, Andrea
I suspect log4net cannot find the logger for your type ImageRepository. As a quick check create a named logger and try calling it.
private static log4net.ILog _logger = log4net.LogManager.GetLogger("FooLog");
And config
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingFile"/>
</root>
<logger name="FooLog">
<level value="DEBUG"/>
<appender-ref ref="RollingFile"/>
</logger>
In theory this should work (as I'm sure you are aware). In general, however, there are two areas to check when you don't get anything logged to a file. The first area I would check would be the file appender itself. Text files can be locked, which can cause messages to be lost. The other thing I would check is to be sure that log4net is properly initialized in the library. It should be, but it doesn't hurt to check. If neither of these solutions help, try turning on the debugging of log4net itself to see what error messages are coming up. Here is a link that shows you how to turn on those messages:
http://haacked.com/archive/2006/09/27/Log4Net_Troubleshooting.aspx
精彩评论