我正在尝试通过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");
我使用以下命令使用mono进行编译:
dmcs -reference:NLog.dll MyApp.cs
我正在使用最新的?来自here的nlog版本,我有4.Net框架的4.0。这个应用程序在Windows 7家用PC(也是.Net 4.0)上工作正常,但似乎在我的XP专业PC上抛出此异常。我无法想象这会有什么区别,但作为一个.Net假人我不知道问题可能是什么。
有没有人见过这个问题,或者对问题是什么有任何见解?
答案 0 :(得分:0)
我不知道为什么(尽管我怀疑它是.Net框架版本问题),但使用nlog v1而不是v2就可以了。
答案 1 :(得分:0)
你使用$ {counter}或NLog布局所需的其他功能吗?