【发布时间】:2015-12-13 07:09:35
【问题描述】:
我使用log4net 来创建日志,但它什么也没做。
这里是app.config:
<?xml version="1.0" encoding="utf-8">
<configuration>
<configSection>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSection>
<log4net>
<appender name="WriteToFile" type="log4net.Appender.FileAppender">
<file value="log.txt" />
<layout ="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="WriteToFile"/>
</root>
</log4net>
</configuration>
我在AssemblyInfo.cs 中有以下行:
[assembly: log4net.Config.XmlConfigur(ConfigFile ="App.config", Watch= true)]
这是一个写入文件的尝试:
private static readonly ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void write()
{
log.Info("Some text here");
}
还有下面一行:
log4net.Config.XmlConfigurator.Configure();
【问题讨论】:
-
试试这个,我觉得对你有帮助。 stackoverflow.com/questions/1321261/…
-
您是否在没有写入权限的文件夹中运行程序?