/
Class1.cs
35 lines (29 loc) · 1.01 KB
/
Class1.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
using System;
using Unity;
using Unity.Interception.PolicyInjection.Pipeline;
using Unity.Interception.PolicyInjection.Policies;
namespace ClassLibrary1
{
internal class ExceptionLoggerCallHandler : ICallHandler
{
public IMethodReturn Invoke(
IMethodInvocation input, GetNextHandlerDelegate getNext)
{
// メソッド呼び出し前のログを出力
Console.WriteLine("Before {0}", input.MethodBase.Name);
// インターセプトしたメソッドを呼び出す
IMethodReturn result = getNext()(input, getNext);
// メソッド呼び出し後のログを出力
Console.WriteLine("After {0}", input.MethodBase.Name);
return result;
}
public int Order { get; set; }
}
public class LoggerAttribute : HandlerAttribute
{
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new ExceptionLoggerCallHandler();
}
}
}