forked from cyq1162/cyqdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDebug.cs
69 lines (67 loc) · 2.09 KB
/
AppDebug.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using CYQ.Data.Cache;
namespace CYQ.Data
{
/// <summary>
/// 应用程序调试类,能截到应用程序所有执行的SQL
/// </summary>
public static class AppDebug
{
private static CacheManage _Cache = CacheManage.LocalInstance;
/// <summary>
/// 正在记录中
/// </summary>
public static bool IsRecording
{
get
{
return _Cache.Contains(_Key);
}
}
private const string _Key = "AppDebug_RecordSQL";// "CYQ.Data.AppDebug_RecordSQL";
private const string _KeyTime = "AppDebug_RecordTime";// "CYQ.Data.AppDebug_RecordTime";
/// <summary>
/// 获取调试信息
/// </summary>
public static string Info
{
get
{
string info = string.Empty;
if (AppConfig.Debug.OpenDebugInfo)
{
info = Convert.ToString(_Cache.Get(_Key));
object time = _Cache.Get(_KeyTime);
if (time != null && time is DateTime)
{
DateTime start = (DateTime)time;
TimeSpan ts = DateTime.Now - start;
info += AppConst.HR + "all execute time is: " + ts.TotalMilliseconds + " (ms)";
}
}
return info;
}
}
/// <summary>
/// 开始记录调试信息
/// </summary>
public static void Start()
{
_Cache.Set(_Key, string.Empty);
_Cache.Set(_KeyTime, DateTime.Now);
}
/// <summary>
/// 停止并清除记录的调试信息
/// </summary>
public static void Stop()
{
_Cache.Remove(_Key);
_Cache.Remove(_KeyTime);
}
internal static void Add(string sql)
{
object sqlObj = _Cache.Get(_Key);
_Cache.Set(_Key, sqlObj + sql);
}
}
}