问题
I want to make use of NLog to log the exception while executing my code, I have installed the required files and included it, the moment I run my web service, I get following error,
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 ---
and I am using NLog in my code as follows,
private static Logger logger = LogManager.GetCurrentClassLogger();,
Can any one tell me where I am wrong.
below is my nlog.config file
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>
回答1:
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.
Indicates that the NLog dll is missing or not the correct version. Check that the dll file in the output is present, and is version 2.1.0.0. NLog dll may been updated but it may not have been copied or deployed to the output directory - hence the error.
The normal dll filename for Nlog is NLog.dll
.
来源:https://stackoverflow.com/questions/20000658/error-in-execution-while-using-nlog