我使用log4net
爲了創建日誌,但它什麼也不做。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();
試試這個,我覺得它對你有幫助。 http://stackoverflow.com/questions/1321261/configuring-log4net-with-xml-file – Brian
你是否在你沒有寫權限的文件夾中運行你的程序? – BeerBaron