Page 1 of 1

List IP address in ErrorLog?

Posted: Thu Oct 22, 2009 5:33 am
by William_firefold
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?

Re: List IP address in ErrorLog?

Posted: Thu Oct 22, 2009 6:42 am
by mazhar
In your global.asax file locate following code block

Code: Select all

// IGNORE HttpExceptions
            if (exception is HttpException) return;
and replace it with following block

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;
            }
Now make a request for some invalid aspx page and then check error log.