Exemplo n.º 1
0
        private static string _renderStackRecordResult(RenderingCollection preparedResult, bool fileSystemLog = true, bool htmlOut = false)
        {
            bool   webEnv       = Dispatcher.EnvType == EnvType.Web;
            string dateStr      = String.Format("{0:yyyy-MM-dd HH:mm:ss:fff}", DateTime.Now);
            string errorFileStr = "";
            string headersStr;
            string stackTraceStr;

            if (htmlOut)
            {
                if (webEnv && !fileSystemLog)
                {
                    headersStr = Exceptions._renderDataTableRows(preparedResult.Headers, htmlOut, false);
                    if (preparedResult.ErrorFileStackTrace.HasValue)
                    {
                        errorFileStr = ErrorFile.Render(preparedResult.ErrorFileStackTrace.Value, StackTraceFormat.Html);
                    }
                    stackTraceStr = Exceptions._renderStackTrace(preparedResult.AllStackTraces, htmlOut, StackTraceFormat.Html, fileSystemLog);
                    return(Exceptions._renderStackRecordResultHtmlResponse(
                               preparedResult, errorFileStr, stackTraceStr, headersStr, dateStr
                               ));
                }
                else
                {
                    headersStr    = Exceptions._renderDataTableRows(preparedResult.Headers, false, false);
                    stackTraceStr = Exceptions._renderStackTrace(preparedResult.AllStackTraces, htmlOut, StackTraceFormat.Json, fileSystemLog);
                    return(Exceptions._renderStackRecordResultHtmlLog(
                               preparedResult, stackTraceStr, headersStr, dateStr
                               ));
                }
            }
            else
            {
                headersStr = Exceptions._renderDataTableRows(preparedResult.Headers, htmlOut, false);
                List <string> processAndThreadId = new List <string>()
                {
                    "Process ID: " + Tools.GetProcessId().ToString()
                };
                if (!webEnv && !fileSystemLog)
                {
                    if (preparedResult.ErrorFileStackTrace.HasValue)
                    {
                        errorFileStr = ErrorFile.Render(preparedResult.ErrorFileStackTrace.Value, StackTraceFormat.Text);
                    }
                    stackTraceStr = Exceptions._renderStackTrace(preparedResult.AllStackTraces, htmlOut, StackTraceFormat.Text, fileSystemLog);
                    processAndThreadId.Add("Thread ID : " + Tools.GetThreadId().ToString());
                    return(Exceptions._renderStackRecordResultConsoleText(
                               preparedResult, String.Join(Environment.NewLine + "   ", processAndThreadId.ToArray()), errorFileStr, stackTraceStr, headersStr, dateStr
                               ));
                }
                else
                {
                    stackTraceStr = Exceptions._renderStackTrace(preparedResult.AllStackTraces, htmlOut, StackTraceFormat.Json, fileSystemLog);
                    if (webEnv)
                    {
                        processAndThreadId.Add("Request ID: " + Tools.GetRequestId().ToString());
                    }
                    processAndThreadId.Add("Thread ID: " + Tools.GetThreadId().ToString());
                    return(Exceptions._renderStackRecordResultLoggerText(
                               preparedResult, String.Join(" | ", processAndThreadId.ToArray()), errorFileStr, stackTraceStr, headersStr, dateStr
                               ));
                }
            }
        }
Exemplo n.º 2
0
        internal static string Render(StackTraceItem errorFileStackTrace, StackTraceFormat format)
        {
            string result         = "";
            string rawFileContent = ErrorFile._readErrorFile(errorFileStackTrace.File.ToString());

            rawFileContent = rawFileContent.Replace("\r", "");
            string[] allFileLines = Regex.Split(rawFileContent, "\n");
            int[]    linesCount   = ErrorFile._errorFileLineDisplayArea;
            int      lineInt      = -1;
            int      columnInt    = -1;

            try {
                if (errorFileStackTrace.Line.Length > 0)
                {
                    lineInt = Convert.ToInt32(errorFileStackTrace.Line);
                }
                if (errorFileStackTrace.Column.Length > 0)
                {
                    columnInt = Convert.ToInt32(errorFileStackTrace.Column);
                }
            } catch { }
            if (lineInt > -1)
            {
                int beginLine;
                int endLine;
                if (lineInt - 1 - linesCount[0] < 0)
                {
                    beginLine      = 1;
                    linesCount[1] += linesCount[0] - (lineInt - 1);
                }
                else
                {
                    beginLine = lineInt - linesCount[0];
                }
                if (lineInt + linesCount[1] > allFileLines.Length)
                {
                    endLine    = allFileLines.Length;
                    beginLine -= (lineInt + linesCount[1]) - allFileLines.Length;
                    if (beginLine < 1)
                    {
                        beginLine = 1;
                    }
                }
                else
                {
                    endLine = lineInt + linesCount[1];
                }
                List <dynamic> linesToRender = new List <dynamic>();
                bool           current;
                for (int i = 1, l = allFileLines.Length + 1; i < l; i++)
                {
                    if (i < beginLine)
                    {
                        continue;
                    }
                    if (i > endLine)
                    {
                        break;
                    }
                    current = (i == lineInt) ? true : false;
                    linesToRender.Add(new {
                        text    = allFileLines[i - 1],
                        current = current,
                        num     = i,
                    });
                }
                result = ErrorFile.RenderErrorLines(errorFileStackTrace.File.ToString(), lineInt, columnInt, linesToRender, format);
            }
            return(result);
        }