我使用了Log4net创建了一个简单的场景,但是我的日志附加器似乎不起作用,因为消息没有被添加到日志文件中。
我将以下内容添加到web.config文件中:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="D:\MyData\Desktop\LogFile.txt" />
<appendToFile value="true" />
<encoding value="utf-8" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
在全局 ASAX 文件中,我已经添加了以下内容:
ILog logger = LogManager.GetLogger(typeof(MvcApplication));
而在Application_Start方法内部:
logger.Info("Starting the application...");
为什么测试日志“启动应用程序…”没有添加到日志文件中?
AssemblyInfo
文件中进行配置。 - LCJ