/// <summary> Log the message after optionally encoding any special characters that might inject into an HTML based log viewer.
        /// This method accepts an exception.
        ///
        /// </summary>
        /// <param name="type">The log type.
        /// </param>
        /// <param name="message">The log message.
        /// </param>
        /// <param name="throwable">The exception to log.
        /// </param>
        private string GetLogMessage(string type, string message, Exception throwable)
        {
            User user = (User)Esapi.Authenticator().GetCurrentUser();

            string clean = message;

            if (((SecurityConfiguration)Esapi.SecurityConfiguration()).LogEncodingRequired)
            {
                clean = Esapi.Encoder().EncodeForHtml(message);
                if (!message.Equals(clean))
                {
                    clean += " (Encoded)";
                }
            }
            if (throwable != null)
            {
                string fqn   = throwable.GetType().FullName;
                int    index = fqn.LastIndexOf('.');
                if (index > 0)
                {
                    fqn = fqn.Substring(index + 1);
                }
                StackTrace st = new StackTrace(throwable, true);

                // Note: Should we have exceptions with null stack traces?

                StackFrame[] frames = st.GetFrames();
                if (frames != null)
                {
                    StackFrame frame = frames[0];
                    clean += ("\n    " + fqn + " @ " + frame.GetType() + "." + frame.GetMethod() + "(" + frame.GetFileName() + ":" + frame.GetFileLineNumber() + ")");
                }
            }
            string msg = "";

            if (user != null)
            {
                msg = type + ": " + user.AccountName + "/" + user.GetLastHostAddress() + " -- " + clean;
            }

            return(msg);
        }
Exemple #2
0
        private string GetLogMessage(string type, string message, Exception throwable)
        {
            User   currentUser = (User)Owasp.Esapi.Esapi.Authenticator().GetCurrentUser();
            string str1        = message;

            if (((SecurityConfiguration)Owasp.Esapi.Esapi.SecurityConfiguration()).LogEncodingRequired)
            {
                str1 = Owasp.Esapi.Esapi.Encoder().EncodeForHtml(message);
                if (!message.Equals(str1))
                {
                    str1 += " (Encoded)";
                }
            }
            if (throwable != null)
            {
                string str2 = throwable.GetType().FullName;
                int    num  = str2.LastIndexOf('.');
                if (num > 0)
                {
                    str2 = str2.Substring(num + 1);
                }
                StackFrame[] frames = new StackTrace(throwable, true).GetFrames();
                if (frames != null)
                {
                    StackFrame stackFrame = frames[0];
                    str1 = str1 + "\n    " + str2 + " @ " + (object)stackFrame.GetType() + "." + (object)stackFrame.GetMethod() + "(" + stackFrame.GetFileName() + ":" + (object)stackFrame.GetFileLineNumber() + ")";
                }
            }
            string str3 = "";

            if (currentUser != null)
            {
                str3 = type + ": " + currentUser.AccountName + "/" + currentUser.GetLastHostAddress() + " -- " + str1;
            }
            return(str3);
        }