aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenSim.Framework/Logger.cs
diff options
context:
space:
mode:
authorlbsa712007-06-18 15:55:30 +0000
committerlbsa712007-06-18 15:55:30 +0000
commit2f072d1e1045d2a0a1ac96487492ac915166b1dc (patch)
treee2f8c6b592e486eac97a3effb33d7825ed84ca39 /Common/OpenSim.Framework/Logger.cs
parentFixed the flashing when crossing a border. (diff)
downloadopensim-SC_OLD-2f072d1e1045d2a0a1ac96487492ac915166b1dc.zip
opensim-SC_OLD-2f072d1e1045d2a0a1ac96487492ac915166b1dc.tar.gz
opensim-SC_OLD-2f072d1e1045d2a0a1ac96487492ac915166b1dc.tar.bz2
opensim-SC_OLD-2f072d1e1045d2a0a1ac96487492ac915166b1dc.tar.xz
* example soft logger by delegate
Diffstat (limited to 'Common/OpenSim.Framework/Logger.cs')
-rw-r--r--Common/OpenSim.Framework/Logger.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/Common/OpenSim.Framework/Logger.cs b/Common/OpenSim.Framework/Logger.cs
new file mode 100644
index 0000000..e7eaa03
--- /dev/null
+++ b/Common/OpenSim.Framework/Logger.cs
@@ -0,0 +1,85 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework
6{
7 public class Logger
8 {
9 public static Logger Instance = new Logger( false );
10
11 public delegate void LoggerMethodDelegate();
12 private delegate bool LoggerDelegate( LoggerMethodDelegate whatToDo );
13
14
15 private LoggerDelegate m_delegate;
16
17 public Logger( bool log )
18 {
19 if( log )
20 {
21 m_delegate = CatchAndLog;
22 }
23 else
24 {
25 m_delegate = DontCatch;
26 }
27 }
28
29 public bool Wrap( LoggerMethodDelegate whatToDo )
30 {
31 return m_delegate( whatToDo );
32 }
33
34
35 private bool CatchAndLog(LoggerMethodDelegate whatToDo)
36 {
37 try
38 {
39 whatToDo();
40 return true;
41 }
42 catch(Exception e)
43 {
44 System.Console.WriteLine( "Exception logged!!! Woah!!!!" );
45 return false;
46 }
47 }
48
49 private bool DontCatch(LoggerMethodDelegate whatToDo)
50 {
51 whatToDo();
52 return true;
53 }
54
55 public class LoggerExample
56 {
57 public void TryWrap()
58 {
59 // This will log and ignore
60 Logger log = new Logger(true);
61
62 log.Wrap(delegate()
63 {
64 Int16.Parse("waa!");
65 });
66
67 // This will throw;
68 try
69 {
70
71 log = new Logger(false);
72
73 log.Wrap(delegate()
74 {
75 Int16.Parse("waa!");
76 });
77 }
78 catch
79 {
80 System.Console.WriteLine("Example barfed!");
81 }
82 }
83 }
84 }
85}