我正在使用 Log4Net 在我的 Web 应用程序中记录异常。
在这里,我找到了一个配置示例:http ://www.cshaptocsharp.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");
但我有错误: