【发布时间】:2011-10-15 10:49:48
【问题描述】:
您好,我尝试使用 NLog 在 App Domain 上记录日志。它是带有 Caliburn Micro 的 WPF 应用程序。
在 MEF 引导程序中,我有以下代码:
static readonly ILog Log = LogManager.GetLog(typeof(NLogLogger));
#region Constructors
public MefBootStrapper()
: base()
{
_msgBox = new MessageBoxes();
_doHandle = true;
}
static MefBootStrapper()
{
LogManager.GetLog = type => new NLogLogger(type);
}
#endregion
#region Exception handling on App Domain
protected override void OnUnhandledException(object sender,
System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
if (_doHandle)
{
Log.Error(e.Exception.InnerException);
_msgBox.ShowException(e.Exception.InnerException);
e.Handled = true;
}
else
{
Log.Error(e.Exception.InnerException);
_msgBox.ShowException(e.Exception);
e.Handled = false;
}
}
#endregion
当我运行应用程序并从视图模型类中抛出异常时,它显示的消息框正常,但异常未记录到文件中。
我尝试在视图模型调用中记录异常:
类似这样的:Log.Error(new Exception("4"));
这项工作,但如果我尝试在 OnUnhandleException 方法中记录异常,它不会工作。为什么?
【问题讨论】:
标签: wpf exception-handling appdomain nlog caliburn.micro