【发布时间】:2013-11-25 20:42:05
【问题描述】:
我想在执行我的代码时使用 NLog 记录异常,我已经安装了所需的文件并包含它,当我运行我的 web 服务时,我得到以下错误,
System.TypeInitializationException: The type initializer for
'Web_Service.Service1' threw an exception. --->System.IO.FileNotFoundException:
Could not load file or assembly 'NLog, Version=2.1.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'
or one of its dependencies. The system cannot find the file specified.
at Web_Service.Service1..cctor()
--- End of inner exception stack trace ---
我在我的代码中使用 NLog,如下所示,
private static Logger logger = LogManager.GetCurrentClassLogger();,
谁能告诉我哪里错了。
下面是我的 nlog.config 文件
for information on customizing logging rules and outputs.
-->
<target xsi:type="File" name ="file" fileName="${basedir}/logs/${shortdate}.log"
layout="
------------${longdate} ${uppercase:${level}} ${message}-------------${newline}
${newline}
Call Site: ${callsite}${newline}
Exception Type: ${exception:format=Type}${newline}
Exception Message: ${exception:format=Message}${newline}
Stack Trace: ${exception:format=StackTrace}${newline}
Additional Info: ${message}${newline}"
/>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="file" />
<logger name ="*" minlevel ="Info" writeTo ="file"/>
</rules>
【问题讨论】:
-
NLog dll 丢失或版本不正确。确保它在您的 bin 文件夹中。
-
在我的 bin 中有 NLog.Extended.dll,你能告诉我你是怎么知道 dll 不正确或丢失的吗?
-
你用nuget包管理器安装nlog包了吗?
-
您需要 nlog.dll 和 nlog.extended.dll。仅当您想使用代码设置 nlog 配置时,才需要 nlog 扩展 dl。
-
不是
NLog.Extended.dll,好像没有NLog.dll