你好,親愛的開發商,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中看到,但沒有傳遞給應用程序。 –