我正在使用Log4Net在我的Web應用程序中記錄異常。Log4net配置錯誤
在這裏,我已經找到一個例子配置:http://www.csharptocsharp.com/log4net-configuration-for-rockin-loggin
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<!--
This writes the log information to the console window. It only logs events
that are at least at the INFO level (which would mean that DEBUG events are not
captured.
-->
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{ABSOLUTE} [%thread] %level %logger - %message%newlineExtra Info: %property{testProperty}%newline%exception"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO"/>
<levelMax value="FATAL"/>
</filter>
</appender>
<!--
This stores information in the log.txt file. It only captures log events
that contain the key word test or error.
-->
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="L:\Name\trunk\Name.Web\log.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="5"/>
<maximumFileSize value="10MB"/>
<staticLogFileName value="true"/>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="test"/>
</filter>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="error"/>
</filter>
<filter type="log4net.Filter.DenyAllFilter"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/>
</layout>
</appender>
<root>
<level value="FATAL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<logger name="Log4NetTest.OtherClass">
<level value="DEBUG"/>
<appender-ref ref="ConsoleAppender"/>
</logger>
</log4net>
</configuration>
在我的課,我有:
protected static readonly ILog log = LogManager.GetLogger(typeof(TemplateController));
,並在我的方法,我有:
log4net.Config.XmlConfigurator.Configure();
//————————–
log.Error("sadi the great");
log.Info("sadi the great");
但我有錯誤:
請發表你的實際配置文件的全部內容。您顯示的分數(?)肯定是無效的XML。另請注意,原因實際上顯示在屏幕上(「根元素丟失」)。 –
我已更新我的問題 – revolutionkpi
您的配置文件中並沒有真正的'保護靜態只讀ILog log = Log ...'部分,是嗎? –