User-33878607 posted
Hi
I have create below HttpModule that will catch exceptions in the Web Appllication:
namespace MyModule
{
public class MyClass:IHttpModule
{
public void Init(HttpApplication context)
{
context.Error += new EventHandler(context_Error);
}
void context_Error(object sender, EventArgs e)
{
//// Get the Last Error in the system
Exception ex = HttpContext.Current.Server.GetLastError();
//Logic to log exception object ex in text file.
}
}
}
Registered in Web Site web.config as follows:
<httpModules>
<add name="MyModule" type="MyModule.MyClass, MyModule"/>
</httpModules>
Asp.net code, i have caused exception purpusefully in asp.net code as follows:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
int a = 1;
int b = 0;
int c = a / b;
}
catch (Exception ex)
{
}
}
Actually i am logging exceptions in text file . But when excpetion occurs in asp.net web site nothing is being logged.
Cheers
Happy Programming