你好,亲爱的开发商,NLOG拒绝,抛出异常
我遇到了一个奇怪的问题与NLOG,
我没有崩溃,但无法找到日志中的用户活动痕迹。
我认为,日志记录不工作...
尝试搜索权限问题等,但似乎都是O.K.
我想调试我的情况问题的记录,所以我创建了下面的
代码来告诉用户,如果它未能创造任何东西:
public static class Log
{
static Log()
{
try
{
AppLogger = LogManager.GetLogger("Megatec.EngineeringMatrix.AppLogger");
ChangeLogger = LogManager.GetLogger("Megatec.EngineeringMatrix.ChangeLogger");
DRCLogger = LogManager.GetLogger("Megatec.EngineeringMatrix.DRCLogger");
if((AppLogger == null) || (ChangeLogger == null) || (DRCLogger == null))
throw new NLogConfigurationException("Configuration does not specify correct loggers");
writeStartupLogEntry();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), @"Failed to load `Megatec.EngineeringMatrix` Loggers.");
throw;
}
}
public static readonly Logger AppLogger;
public static readonly Logger ChangeLogger;
public static readonly Logger DRCLogger;
与下面的配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
<targets>
<target xsi:type="File" name="AppLogFile" createDirs="true" fileName="c:/log?s/${processname}/${logger}_${shortdate}.log"
layout=">> ${time} ${uppercase:${level}} ${callsite} ${message} ${exception:format=tostring}" />
<target xsi:type="File" name="ChangeLogFile" createDirs="true" fileName="c:/log?s/${processname}/${logger}_${shortdate}.log"
layout=">> ${date} ${message} ${exception:format=tostring}" />
<target xsi:type="File" name="DRCLogFile" createDirs="true" fileName="c:/logs/${processname}/${logger}_${shortdate}.log"
layout=">> ${date} ${message} ${exception:format=tostring}" />
</targets>
<rules>
<logger name="Megatec.EngineeringMatrix.AppLogger" minlevel="Trace" writeTo="AppLogFile" />
<logger name="Megatec.EngineeringMatrix.ChangeLogger" minlevel="Trace" writeTo="ChangeLogFile" />
<logger name="Megatec.EngineeringMatrix.DRCLogger" minlevel="Trace" writeTo="DRCLogFile" />
</rules>
</nlog>
明显我写了一个BAAD配置,因为无法创建目录c:\lo?gs
。
不过,我仍然没有得到消息
MessageBox.Show(ex.ToString(), @"Failed to load 'Megatec.EngineeringMatrix'
甚至AppLogger.Info()
跳过例外...
什么我写的日志,但应用程序不知道它.. 。
在调试,我可以捕获异常,看看它是由NLOG处理,
我怎样才能抓住它从我的代码?
您是否尝试过的故障排除步骤在这里:http://nlog-project.org/wiki/Configuration_file#Troubleshooting_logging?默认情况下,日志记录异常被吞噬。 – Joe
是的,我添加了necessery配置参数,你可以看到.. 但仍然。我可以在internalLog中看到,但没有传递给应用程序。 –