使用EvtExportLog函数 ,当前无法为Path和/或Query参数指定正确的值。 我的目标是导出本地应用程序和系统事件日志。 我试过了: 具有以下P / Invoke定义: 不幸的是,该函数返回false和最后一个错误代码2( ERROR_FILE_NOT_F ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我有一个正在生产的WPF应用程序,由于System.ObjectDisposedException,该应用程序正在用AppCrash错误填充Windows应用程序事件日志。 AppCrash专门指向我的应用程序SampleApplication.exe。 另外,该应用程序在无法连接到网络的系统上运行(因此没有远程调试的可能性),我很难找到问题所在。
我附加了两个事件处理程序,以捕获和记录所有未处理的异常。 这些适用于所有其他异常。 我不确定这些System.ObjectDisposedExceptions在进入事件日志之前如何被捕获,以及为什么应用程序实际上没有崩溃。 它保持运行正常。
以下是应用程序的异常事件处理程序以及将它们连接起来的App构造函数:
public App() : base()
{
System.Windows.Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
}
void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Console.WriteLine(e.Exception.Message);
Console.WriteLine(e.Exception.StackTrace);
LogException(e.Exception);
e.Handled = true;
}
void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
if (unhandledExceptionEventArgs.ExceptionObject is Exception)
{
var e = (Exception)unhandledExceptionEventArgs.ExceptionObject;
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
LogException((Exception)unhandledExceptionEventArgs.ExceptionObject);
}
}
void LogException(Exception e)
{
Exception tmp = e;
while (tmp.InnerException != null)
tmp = tmp.InnerException;
string errorMessage = string.Format("An unhandled exception occurred: {0}", tmp.Message);
System.Windows.MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
EventLogService.AddLog(EventLogSourceTypes.Error, errorMessage, DateTime.UtcNow, e.StackTrace);
}
我不确定这些是否与我的问题相关,即:
如何捕获这些异常并记录详细信息,而不是填充Windows应用程序事件日志? 而且,该应用程序继续可以正常运行,因此尽管它们是AppCrash条目,但该应用程序实际上并未崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.