1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Text;
|
21
|
|
using System.Reflection;
|
22
|
|
using Seasar.Framework.Log;
|
23
|
|
|
24
|
|
namespace Seasar.Framework.Aop.Interceptors
|
25
|
|
{
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
|
public class TraceInterceptor : AbstractInterceptor
|
30
|
|
{
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
|
private static Logger logger_ = Logger.GetLogger(typeof(TraceInterceptor));
|
35
|
|
|
36
|
|
#region IMethodInterceptor クラス
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
8
|
public override object Invoke(IMethodInvocation invocation)
|
44
|
|
{
|
45
|
8
|
MethodBase mb = invocation.Method;
|
46
|
8
|
StringBuilder buf = new StringBuilder(100);
|
47
|
8
|
buf.Append(mb.DeclaringType.FullName);
|
48
|
8
|
buf.Append("#");
|
49
|
8
|
buf.Append(mb.Name);
|
50
|
8
|
buf.Append("(");
|
51
|
8
|
object[] args = invocation.Arguments;
|
52
|
8
|
if(args != null && args.Length > 0)
|
53
|
|
{
|
54
|
0
|
for(int i=0;i<args.Length;i++)
|
55
|
|
{
|
56
|
|
buf.Append(args[i]);
|
57
|
|
buf.Append(", ");
|
58
|
|
}
|
59
|
0
|
buf.Length = buf.Length - 2;
|
60
|
|
}
|
61
|
8
|
buf.Append(")");
|
62
|
8
|
logger_.Debug("BEGIN " + buf.ToString());
|
63
|
8
|
object ret = null;
|
64
|
8
|
Exception cause = null;
|
65
|
8
|
try
|
66
|
|
{
|
67
|
8
|
ret = invocation.Proceed();
|
68
|
8
|
buf.Append(" : ");
|
69
|
8
|
buf.Append(ret);
|
70
|
|
}
|
71
|
|
catch(Exception ex)
|
72
|
|
{
|
73
|
0
|
buf.Append(" Exception:");
|
74
|
0
|
buf.Append(ex);
|
75
|
0
|
cause = ex;
|
76
|
|
}
|
77
|
8
|
logger_.Debug("END " + buf.ToString());
|
78
|
8
|
if(cause == null)
|
79
|
|
{
|
80
|
8
|
return ret;
|
81
|
|
}
|
82
|
|
else
|
83
|
|
{
|
84
|
0
|
throw cause;
|
85
|
|
}
|
86
|
|
}
|
87
|
|
|
88
|
|
#endregion
|
89
|
|
|
90
|
|
}
|
91
|
|
}
|
92
|
|
|