I have an app. I'm trying to write log in Windows Event Viewer
when its crashing. I found Write to Windows Application Event Log and I'm using DispatcherUnhandledExceptionEventHandler
for catching unhandled exception. I'm setting it in constructor of app like:
DispatcherUnhandledException += MyApplication_DispatcherUnhandledException;
and write log like this:
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry(exceptionMessage, EventLogEntryType.Error);
}
Log creates, but in Run
method of System.Windows.Application
occurs another exception and windows adds this error in Event Viewer with another Id, source....
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Exception at ServerApp.MainWindow..ctor()
Exception Info: System.Windows.Markup.XamlParseException at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri) at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri) at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean) at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext) at System.Windows.Application.LoadComponent(System.Uri, Boolean) at System.Windows.Application.DoStartup()
How can I write only my log in event viewer?