【发布时间】:2014-01-13 14:29:12
【问题描述】:
在我的 C# 中,我正在使用一个库(Outlook 插件)。
我正在为 .NET 3.5 使用 NLog
问题是在我的开发机器上,有时 NLog 不会将日志写入文件。
我使用的是 NLog 2.0.0.0 版本,问题出现在 Windows 8.1 Pro 上
这里是 App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}\\AppName\\Logs\\log.txt"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="30"
layout="${date:format=yyyy-MM-dd HH\:mm\:ss} ${level:uppercase=true} ${logger} - ${message} ${exception:format=tostring}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file"/>
</rules>
</nlog>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
在发行版中,目前我不包含文件NLog.config,但也包含它,我没有看到任何变化
以下是问题发生的方法, 我应该在我的发行版中包含特殊库吗? (例如 stdole.dll 之类的?)
private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
{
String aversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
log.Debug("AddinStartupComplete called version: {0}", aversion);
}
【问题讨论】:
-
您是否确定了未记录的程序或逻辑部分?可能错误发生在该逻辑之前,因此没有被记录
-
是的,实际上我有一个日志行,在模块完成初始化时调用,并且调用此行不会对日志文件产生任何写入。
-
如果您在该指令之前调用 log.Debug 它会被记录?
-
不,我没有,但奇怪的是,当我在调试模式下启动托管应用程序(在本例中为 Outlook)时,日志文件会正确生成
标签: c# .net configuration nlog