Пример #1
0
 /// <summary>
 /// 在应用程序启动时注册Model
 /// </summary>
 public static void Start()
 {
     if (DebuggerConfiguration.Instance().EnableSqlTraceOrResponseTime())
     {
         DynamicModuleUtility.RegisterModule(typeof(SqlTraceHttpModule));
         PetaPocoDatabase.SqlTraceEnabled = DebuggerConfiguration.Instance().EnableSqlTrace();
     }
 }
Пример #2
0
        /// <summary>
        /// 实例化Debugger配置
        /// </summary>
        public static DebuggerConfiguration Instance()
        {
            if (debuggerConfiguration == null)
            {
                debuggerConfiguration = new DebuggerConfiguration();
            }

            return(debuggerConfiguration);
        }
Пример #3
0
        public void ProcessRequest(HttpContext context, List <SqlTraceEntity> sqlTraces, Stopwatch sw)
        {
            var request = context.Request;

            if (!IsRoutedRequest(request))
            {
                return;
            }
            sw.Stop();

            string generatedUrlInfo = string.Empty;
            var    requestContext   = request.RequestContext;

            string htmlFormat = @"<html>
                                    <div id=""haackroutedebugger"" style=""background-color: #fff;"">
                                        <style>
                                            #haackroutedebugger, #haackroutedebugger td, #haackroutedebugger th {{background-color: #fff; font-family: verdana, helvetica, san-serif; font-size: small;}}
                                            #haackroutedebugger tr.header td, #haackroutedebugger tr.header th {{background-color: #ffc;}}
                                        </style>
                                        <hr style=""width: 100%; border: solid 1px #000; margin:0; padding:0;"" />
                                        <h1 style=""margin: 0; padding: 4px; border-bottom: solid 1px #bbb; padding-left: 10px; font-size: 1.2em; background-color: #ffc;"">Sql 跟踪</h1>
                                        <div id=""main"" style=""margin-top:0; padding-top:0"">
                                            <p style=""font-size: .9em; padding-top:0"">
                                            </p>
                                            <p style=""font-size: .9em;"">
                                                 <code></code>
                                            </p>
                                            {2}
                                            {1}
                                            <br/>
                                            <hr style=""clear: both;"" />
                                            <table border=""1"" cellpadding=""3"" cellspacing=""0"">
                                                {0}
                                            </table>
                                        </div>
                                    </div>";

            string sqls = string.Empty;

            if (sqlTraces != null)
            {
                if (DebuggerConfiguration.Instance().SqlTraceToPage())
                {
                    string[] sqlTypes = new string[] { "select", "insert", "update", "delete" };
                    foreach (var type in sqlTypes.ToList())
                    {
                        sqls += OutSql(sqlTraces, type);
                    }
                }

                if (DebuggerConfiguration.Instance().SqlTraceToLog())
                {
                    ILog log4net = LogManager.GetLogger("ExceptionLogger");
                    foreach (SqlTraceEntity sqlTrace in sqlTraces.ToList())
                    {
                        log4net.Debug(sqlTrace.Sql + "\t\t执行时间" + sqlTrace.ElapsedMilliseconds + "ms");
                    }
                }
            }

            string responseTime = string.Empty;

            if (DebuggerConfiguration.Instance().EnableResponseTime())
            {
                responseTime = @"<div style=""float: left; margin-left: 10px;"">
                                    <table border=""1"" width=""300"">
                                        <caption style=""font-weight: bold;"">页面响应时间</caption>
                                        <tr class=""header""><td>" + sw.ElapsedMilliseconds + @"ms</td></tr>
                                    </table>
                                </div>";
            }

            sw.Reset();
            sqlTraces.Clear();
            if (DebuggerConfiguration.Instance().SqlTraceToPage())
            {
                context.Response.Write(string.Format(htmlFormat, sqls, responseTime, generatedUrlInfo));
            }
        }