예제 #1
0
        /// <summary>
        /// Logs an exception and its context to the error log.
        /// </summary>
        /// <param name="e">The e.</param>
        /// <param name="httpContext">The HTTP context.</param>
        protected virtual void LogException(Exception e, HttpContext httpContext)
        {
            var serviceLog = ServiceLogManager.Get <HttpErrorTrapModule>();

            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            try
            {
                var b = new StringBuilder();
                using (var w = XmlWriter.Create(b))
                {
                    w.WriteStartElement("error");
                    new HttpError(e, httpContext).ToXml(w);
                    w.WriteEndElement();
                }
                string errorText = b.ToString();
                // log based on status code
                var httpException = (e as HttpException);
                if (httpException != null)
                {
                    int statusId = httpException.GetHttpCode();
                    switch ((int)Math.Floor((double)(statusId / 100M)))
                    {
                    case 4:
                        serviceLog.Information(errorText);
                        break;

                    default:
                        serviceLog.Fatal(errorText);
                        break;
                    }
                }
                else
                {
                    serviceLog.Fatal(errorText);
                }
            }
            catch (Exception localException) { Trace.WriteLine(localException); }
        }