We need to be able to see where our errors are coming from.
For example, with a 404 error, we need some way to append IP address of the user who cause it to the error log message. This could be either a new column on the errorlog, or a string tacked on to the error message.
Is this possible?
List IP address in ErrorLog?
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: List IP address in ErrorLog?
In your global.asax file locate following code block
and replace it with following block
Now make a request for some invalid aspx page and then check error log.
Code: Select all
// IGNORE HttpExceptions
if (exception is HttpException) return;
Code: Select all
// IGNORE HttpExceptions
if (exception is HttpException)
{
HttpException httpException = (HttpException)exception;
if (httpException.GetHttpCode() == 404)
{
string message = "404 error occured by request for '{0}' made from {1}";
message = string.Format(message, ctx.Request.Url.ToString(), ctx.Request.ServerVariables["REMOTE_ADDR"]);
Logger.Error(message);
}
return;
}