Follow in Twitter & Facebook

Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools

Saturday, August 4, 2012

Write exception to Event Log in Asp.Net C#.Net

In this article we will discuss how to write exception to Event Log in Asp.Net.  You can check my last article on Exception Class in Asp.Net C#.Net

Event log will be accessible from Start -> Run -> eventvwr. To write the exception message in the Event log is now easy in .Net by use of the namespace System.Diagnostics;

Below is the code to write to event log:

using System.Diagnostics;

// Code
catch (System.Exception ex)
EventLog log = new EventLog();
log.Source = "Comes from .Net Application";
log.WriteEntry(ex.Message, EventLogEntryType.Error);

// Clean up block.

Here in the above code the exception message will be written in the event log with source as "Comes from .Net Application".

Now open the event viewer window ( Start -> Run -> eventvwr ) and Navigate to Windows Logs -> Application , You will able to see the error message.

0 on: "Write exception to Event Log in Asp.Net C#.Net"