Mercurial > pub > bltoolkit
comparison HowTo/Aspects/LoggingAspect.cs @ 0:f990fcb411a9
Копия текущей версии из github
| author | cin |
|---|---|
| date | Thu, 27 Mar 2014 21:46:09 +0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f990fcb411a9 |
|---|---|
| 1 using System; | |
| 2 using System.Threading; | |
| 3 | |
| 4 using NUnit.Framework; | |
| 5 | |
| 6 using BLToolkit.Aspects; | |
| 7 using BLToolkit.Reflection; | |
| 8 | |
| 9 namespace HowTo.Aspects | |
| 10 { | |
| 11 [TestFixture] | |
| 12 public class LoggingAspectTest | |
| 13 { | |
| 14 [/*[a]*/Log/*[/a]*/] | |
| 15 public /*[a]*/abstract/*[/a]*/ class TestClass | |
| 16 { | |
| 17 // Here we customize the logging settings. | |
| 18 // This call will be logged in spite of default settings. | |
| 19 // | |
| 20 [/*[a]*/Log/*[/a]*/(/*[a]*/MinCallTime=50/*[/a]*/)] | |
| 21 public /*[a]*/virtual/*[/a]*/ void Test1(int i) | |
| 22 { | |
| 23 Thread.Sleep(/*[a]*/100/*[/a]*/); | |
| 24 } | |
| 25 | |
| 26 // This call is not going to be logged (see default settings below). | |
| 27 // | |
| 28 public /*[a]*/virtual/*[/a]*/ void Test2(DateTime dt) | |
| 29 { | |
| 30 Thread.Sleep(/*[a]*/100/*[/a]*/); | |
| 31 } | |
| 32 | |
| 33 // By default exception calls are logged. | |
| 34 // | |
| 35 public /*[a]*/virtual/*[/a]*/ void Test3(string s) | |
| 36 { | |
| 37 throw new ApplicationException("Test exception."); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 [Test] | |
| 42 public void Test() | |
| 43 { | |
| 44 // By setting MinCallTime to some value, we prevent logging any call | |
| 45 // which is shorter than the provided value. | |
| 46 // | |
| 47 LoggingAspect.MinCallTime = /*[a]*/1000/*[/a]*/; | |
| 48 | |
| 49 TestClass t = /*[a]*/TypeAccessor/*[/a]*/<TestClass>.CreateInstance(); | |
| 50 | |
| 51 t.Test1(1); | |
| 52 t.Test2(DateTime.Now); | |
| 53 | |
| 54 try | |
| 55 { | |
| 56 t.Test3("3"); | |
| 57 } | |
| 58 catch | |
| 59 { | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 } |
