我正在尝试通过 nlog 登录到控制台并遇到异常:
Unhandled Exception: System.TypeInitializationException: The type initializer fo
r 'MyApp' threw an exception. ---> System.Configuration.ConfigurationEr
rorsException: An error occurred creating the configuration section handler for
nlog: Exception occurred when loading configuration from C:\MyApp\MyApp.exe.config (C:\MyApp\MyApp.exe.config line 14) --->
NLog.NLogConfigurationException: Exception occurred when loading configuration f
rom C:\MyApp\MyApp.exe.config ---> System.ArgumentException: T
arget cannot be found: 'Console'
at NLog.Config.Factory`2.CreateInstance(String name)
at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement tar
getsElement)
at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogEl
ement, String baseDirectory)
at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content,
String baseDirectory)
at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fi
leName, Boolean ignoreErrors)
--- End of inner exception stack trace ---
at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fi
leName, Boolean ignoreErrors)
at NLog.Config.XmlLoggingConfiguration..ctor(XmlElement element, String fileN
ame)
at NLog.Config.ConfigSectionHandler.System.Configuration.IConfigurationSectio
这是我的配置文件:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
<targets>
<target name="c" type="Console" />
<!--<target name="logfile" type="File" fileName="log.txt" archiveAboveSize="10240" maxArchiveFiles="-1" />-->
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="c" />
</rules>
</nlog>
</configuration>
以下是相关代码:
private static Logger logger = LogManager.GetLogger("MyApp");
我正在使用以下命令编译单声道:
dmcs -reference:NLog.dll MyApp.cs
我用的是最新的?来自这里的 nlog 版本,我有 .Net 框架的 4.0。这个应用程序在 Windows 7 家用 PC(也是 .Net 4.0)上运行良好,但似乎在我的 XP pro PC 上抛出了这个异常。我无法想象这会有什么不同,但作为一个.Net 假人,我不知道问题可能是什么。
有没有人以前见过这个或对问题可能有任何见解?