List IP address in ErrorLog?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

List IP address in ErrorLog?

Post by William_firefold » Thu Oct 22, 2009 5:33 am

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?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: List IP address in ErrorLog?

Post by mazhar » Thu Oct 22, 2009 6:42 am

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.

Post Reply