How to see asp.net EVENT errors in IIS 7.5?
At the moment I use EVENT开发者_运维问答 VIEWER in Administrative Tool
to see some nested Asp Errors details for some pages of my website locally.
At the moment I deploying my website on the Server where I have access only to IIS 7.5 and its Logs.
I would like to know if is possible see errors for my ASP.NET directly in IIS or in some other way. Unfortunately using my website I'm not able to see the details for my errors.
Thanks.
we are using something like this in a small ASP.NET application we have:
protected void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
try
{
var userName = "<USERNAME not available...>";
if (HttpContext.Current != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity != null)
{
userName = HttpContext.Current.User.Identity.Name;
}
Exception exc = Server.GetLastError();
var logger = new IEMLogger();
logger.Error(string.Format("Application_Error - user: {0}", userName), exc);
// Clear the error from the server
Server.ClearError();
}
catch (Exception /*exc*/)
{
// DOES NOTHING:
// no recursive error reports in case the logging fails...
}
}
this is using a very defensive approach checking also for context null, current user null and so on. the IEMLogger is our wrapper to LogçNet so we do not have dependencies of LogçNet spread all around...
Edit: please notice that this Application_Error event handler in Global.asax is the last resort of exception handler you should have, this catches all unhandled exceptions but does NOT replace the try/catch blocks you should have anyway in your application classes. Have those try catch as needed in the code of your application and use the same approach with a logger class which logs the exceptions at the very places where exceptions are thrown... this depends on your overall approach to exception and error handling, then if you go for Log4Net, NLog or other loggers everything is really a detail...
You can add a website or page so will show you the event-log (Protect it with password/key ;))
Here is an example so you can use for doing so http://www.aspheute.com/english/20000811.asp
What we do is hook into the Application_Error event in Global.asax, get a reference to the error using Context.Server.GetLastError()
and log to our own Event table.
Then you can simply bind this to an GridView, or extend with search functionality etc.
You can use the following method to see for Errors in Event Viewer.
To open Event Viewer,
1) click Start,
2) click Control Panel,
3) click Performance and Maintenance,
4) click Administrative Tools,
5) and then double-click Event Viewer.
精彩评论