【问题标题】:Error in execution while using NLog使用 NLog 时执行错误
【发布时间】: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

标签: c# asp.net nlog


【解决方案1】:

System.IO.FileNotFoundException:

无法加载文件或程序集“NLog,版本=2.1.0.0,文化=中性,PublicKeyToken=5120e14c03d0593c” 或其依赖项之一。

系统找不到指定的文件。

表示 NLog dll 丢失或版本不正确。检查输出中的 dll 文件是否存在,并且版本为 2.1.0.0。 NLog dll 可能已更新,但可能尚未复制或部署到输出目录 - 因此出现错误。

Nlog 的正常 dll 文件名是NLog.dll

【讨论】:

猜你喜欢
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 2018-01-09
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多