Can you point me to some tutorial or samples on how I can log all un-handled exceptions that are occurring on my mvc web app using log4net. Thank you
相关问题
- Sorting 3 numbers without branching [closed]
- 最新的log4net是不是不支持写入到mysql了。
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- MVC-Routing,Why i can not ignore defaults,The matc
I paste below the code I use on my global.asax that seems to satisfy me for now.. I am getting all unhandled exceptions on my log4net generated log files..
For ASP.NET applications you like to use the
System.Web.HttpApplication.Error
event which is placed inGlobal.asax
file.watch Managing unhandled exceptions
Without being facetious here you go.
Assuming you are using .net 3.5, you could use extension methods, and extend System.Exception and add a Log(log4net.ILog log) method, then wherever you catch an exception in your app, assuming you've setup the Log instance correctly, then you easily do it. Your extension class could grow quite a bit, with various overloads for Debug, Info, Warn, Error and Fatal etc.
There is no built-in support for this in log4net. You should implement the Application_Error event in Global.asax and call your log4net logger there. The event will be triggered for all unhandled events in your app.
You might be interested to check out what Aspect Oriented Programming (AOP) is.
We accomplished this with Post sharp (only - we didn't use log4net but custom tracer).
Just check out first if log4net haven't something for this 'out-of-the-box'. I'm not sure about that.