The example will show how to use event log in your application
The Code
private void button1_Click(object sender, EventArgs e) { try { string[] a = new string[3]; a[4] = "test"; } catch (Exception ex) { LogError(ex); } } public void LogError(Exception ex) { string EventLogSourceName = "Example Log Error"; int EventLogErrorCode = 99; string msg = "The application encountered an unknown error:"; msg += "\r\nExecuting Method: " + new System.Diagnostics.StackFrame(1, false).GetMethod().Name; msg += "\r\nError Message: " + ex.Message; EventLog.WriteEntry(EventLogSourceName, msg, EventLogEntryType.Error, EventLogErrorCode); MessageBox.Show(msg, "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); }
*The code will get run time error because you need to run application as administrator.
The Output - Event Viewer
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment