aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common
diff options
context:
space:
mode:
Diffstat (limited to 'Common')
-rw-r--r--Common/OpenSim.Framework/Logger.cs85
-rw-r--r--Common/OpenSim.Framework/OpenSim.Framework.csproj3
-rw-r--r--Common/OpenSim.Framework/OpenSim.Framework.dll.build1
3 files changed, 89 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}
diff --git a/Common/OpenSim.Framework/OpenSim.Framework.csproj b/Common/OpenSim.Framework/OpenSim.Framework.csproj
index 060e471..f9a4f2d 100644
--- a/Common/OpenSim.Framework/OpenSim.Framework.csproj
+++ b/Common/OpenSim.Framework/OpenSim.Framework.csproj
@@ -102,6 +102,9 @@
102 <Compile Include="IRegionCommsListener.cs"> 102 <Compile Include="IRegionCommsListener.cs">
103 <SubType>Code</SubType> 103 <SubType>Code</SubType>
104 </Compile> 104 </Compile>
105 <Compile Include="Logger.cs">
106 <SubType>Code</SubType>
107 </Compile>
105 <Compile Include="LoginService.cs"> 108 <Compile Include="LoginService.cs">
106 <SubType>Code</SubType> 109 <SubType>Code</SubType>
107 </Compile> 110 </Compile>
diff --git a/Common/OpenSim.Framework/OpenSim.Framework.dll.build b/Common/OpenSim.Framework/OpenSim.Framework.dll.build
index 524255c..ab511f2 100644
--- a/Common/OpenSim.Framework/OpenSim.Framework.dll.build
+++ b/Common/OpenSim.Framework/OpenSim.Framework.dll.build
@@ -15,6 +15,7 @@
15 <include name="AuthenticateSessionBase.cs" /> 15 <include name="AuthenticateSessionBase.cs" />
16 <include name="BlockingQueue.cs" /> 16 <include name="BlockingQueue.cs" />
17 <include name="IRegionCommsListener.cs" /> 17 <include name="IRegionCommsListener.cs" />
18 <include name="Logger.cs" />
18 <include name="LoginService.cs" /> 19 <include name="LoginService.cs" />
19 <include name="RegionCommsListener.cs" /> 20 <include name="RegionCommsListener.cs" />
20 <include name="Remoting.cs" /> 21 <include name="Remoting.cs" />