2013-11-15 179 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