8
我試圖使用log4net。當我啓動應用程序時,它會創建日誌文件,但無論我多次呼叫Log.Info("Application Started");
,它都保持爲空。我研究了Google返回的前兩頁,我的代碼似乎與所有示例相匹配。log4net日誌被創建,但仍爲空
代碼:
[assembly: XmlConfigurator(Watch = true)]
namespace Generator
{
public class Run
{
private static readonly log4net.ILog Log =
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public List<BILL_RUN> PerformBillRun()
{
XmlConfigurator.Configure();
Log.Info("Application Started");
var enabled = Log.IsInfoEnabled; //This is true
}
}
}
的app.config
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="log-files.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
任何指針,以什麼可能是錯的?
將''添加到您的配置的開始標記以查看更多信息(假設您有一個控制檯來查看輸出)也很有用) –
Ryan
2015-04-14 05:27:04