2013-11-15 178 views
1

我想在执行我的代码时使用NLog记录异常,我安装了所需的文件并将其包含在内,当我运行我的web服务时,出现以下错误,使用NLog执行时出错

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> 

+0

NLog dll缺失或不正确的版本。确保它在您的bin文件夹中。 – Kami

+0

在我的箱子里我有NLog.Extended.dll,你能告诉我你怎么知道该DLL不正确或丢失。 – Reshma

+0

您是否使用nuget包管理器来安装nlog包? – th1rdey3

回答

3

System.IO.FileNotFoundException:找不到

无法加载文件或程序集“NLOG,版本= 2.1.0.0,文化=中立,PublicKeyToken = 5120e14c03d0593c' 或它的一个依赖关系。

系统找不到指定的文件。

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

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

+0

你能告诉我如何得到NLog.dll ..? – Reshma

+0

对不起..愚蠢的问题..我从网上下载...反正..谢谢澄清.. – Reshma

+1

@Reshma使用NuGet - http://www.nuget.org/packages/NLog/或手动下载 - http: //nlog-project.org/download/ – Kami