diff options
author | UbitUmarov | 2017-08-30 22:24:07 +0100 |
---|---|---|
committer | UbitUmarov | 2017-08-30 22:24:07 +0100 |
commit | 41e8b9f91ff73fd4d18aae1e467446563f94c33f (patch) | |
tree | 363e12392f731fdcd2b60356ec946cd4ad93cd5a /Prebuild/src/Core/Utilities/Log.cs | |
parent | Merge branch 'master' into httptests (diff) | |
download | opensim-SC-41e8b9f91ff73fd4d18aae1e467446563f94c33f.zip opensim-SC-41e8b9f91ff73fd4d18aae1e467446563f94c33f.tar.gz opensim-SC-41e8b9f91ff73fd4d18aae1e467446563f94c33f.tar.bz2 opensim-SC-41e8b9f91ff73fd4d18aae1e467446563f94c33f.tar.xz |
update Prebuild with WhiteCore version
Diffstat (limited to 'Prebuild/src/Core/Utilities/Log.cs')
-rw-r--r-- | Prebuild/src/Core/Utilities/Log.cs | 434 |
1 files changed, 217 insertions, 217 deletions
diff --git a/Prebuild/src/Core/Utilities/Log.cs b/Prebuild/src/Core/Utilities/Log.cs index cd95633..4df3def 100644 --- a/Prebuild/src/Core/Utilities/Log.cs +++ b/Prebuild/src/Core/Utilities/Log.cs | |||
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted |
6 | provided that the following conditions are met: | 6 | provided that the following conditions are met: |
7 | 7 | ||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions |
9 | and the following disclaimer. | 9 | and the following disclaimer. |
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | 10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions |
11 | and the following disclaimer in the documentation and/or other materials provided with the | 11 | and the following disclaimer in the documentation and/or other materials provided with the |
12 | distribution. | 12 | distribution. |
13 | * The name of the author may not be used to endorse or promote products derived from this software | 13 | * The name of the author may not be used to endorse or promote products derived from this software |
14 | without specific prior written permission. | 14 | without specific prior written permission. |
15 | 15 | ||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, |
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
@@ -28,74 +28,74 @@ using System.IO; | |||
28 | 28 | ||
29 | namespace Prebuild.Core.Utilities | 29 | namespace Prebuild.Core.Utilities |
30 | { | 30 | { |
31 | /// <summary> | 31 | /// <summary> |
32 | /// | 32 | /// |
33 | /// </summary> | 33 | /// </summary> |
34 | public enum LogType | 34 | public enum LogType |
35 | { | 35 | { |
36 | /// <summary> | 36 | /// <summary> |
37 | /// | 37 | /// |
38 | /// </summary> | 38 | /// </summary> |
39 | None, | 39 | None, |
40 | /// <summary> | 40 | /// <summary> |
41 | /// | 41 | /// |
42 | /// </summary> | 42 | /// </summary> |
43 | Info, | 43 | Info, |
44 | /// <summary> | 44 | /// <summary> |
45 | /// | 45 | /// |
46 | /// </summary> | 46 | /// </summary> |
47 | Warning, | 47 | Warning, |
48 | /// <summary> | 48 | /// <summary> |
49 | /// | 49 | /// |
50 | /// </summary> | 50 | /// </summary> |
51 | Error | 51 | Error |
52 | } | 52 | } |
53 | 53 | ||
54 | /// <summary> | 54 | /// <summary> |
55 | /// | 55 | /// |
56 | /// </summary> | 56 | /// </summary> |
57 | [Flags] | 57 | [Flags] |
58 | public enum LogTargets | 58 | public enum LogTargets |
59 | { | 59 | { |
60 | /// <summary> | 60 | /// <summary> |
61 | /// | 61 | /// |
62 | /// </summary> | 62 | /// </summary> |
63 | None = 0, | 63 | None = 0, |
64 | /// <summary> | 64 | /// <summary> |
65 | /// | 65 | /// |
66 | /// </summary> | 66 | /// </summary> |
67 | Null = 1, | 67 | Null = 1, |
68 | /// <summary> | 68 | /// <summary> |
69 | /// | 69 | /// |
70 | /// </summary> | 70 | /// </summary> |
71 | File = 2, | 71 | File = 2, |
72 | /// <summary> | 72 | /// <summary> |
73 | /// | 73 | /// |
74 | /// </summary> | 74 | /// </summary> |
75 | Console = 4 | 75 | Console = 4 |
76 | } | 76 | } |
77 | 77 | ||
78 | /// <summary> | 78 | /// <summary> |
79 | /// Summary description for Log. | 79 | /// Summary description for Log. |
80 | /// </summary> | 80 | /// </summary> |
81 | public class Log : IDisposable | 81 | public class Log : IDisposable |
82 | { | 82 | { |
83 | #region Fields | 83 | #region Fields |
84 | 84 | ||
85 | private TextWriter m_Writer; | 85 | private TextWriter m_Writer; |
86 | private LogTargets m_Target = LogTargets.Null; | 86 | private LogTargets m_Target = LogTargets.Null; |
87 | bool disposed; | 87 | bool disposed; |
88 | 88 | ||
89 | #endregion | 89 | #endregion |
90 | 90 | ||
91 | #region Constructors | 91 | #region Constructors |
92 | 92 | ||
93 | /// <summary> | 93 | /// <summary> |
94 | /// Initializes a new instance of the <see cref="Log"/> class. | 94 | /// Initializes a new instance of the <see cref="Log"/> class. |
95 | /// </summary> | 95 | /// </summary> |
96 | /// <param name="target">The target.</param> | 96 | /// <param name="target">The target.</param> |
97 | /// <param name="fileName">Name of the file.</param> | 97 | /// <param name="fileName">Name of the file.</param> |
98 | public Log(LogTargets target, string fileName) | 98 | public Log(LogTargets target, string fileName) |
99 | { | 99 | { |
100 | m_Target = target; | 100 | m_Target = target; |
101 | 101 | ||
@@ -111,166 +111,166 @@ namespace Prebuild.Core.Utilities | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | #endregion | 114 | #endregion |
115 | 115 | ||
116 | #region Public Methods | 116 | #region Public Methods |
117 | 117 | ||
118 | /// <summary> | 118 | /// <summary> |
119 | /// Writes this instance. | 119 | /// Writes this instance. |
120 | /// </summary> | 120 | /// </summary> |
121 | public void Write() | 121 | public void Write() |
122 | { | 122 | { |
123 | Write(string.Empty); | 123 | Write(string.Empty); |
124 | } | 124 | } |
125 | 125 | ||
126 | /// <summary> | 126 | /// <summary> |
127 | /// Writes the specified MSG. | 127 | /// Writes the specified MSG. |
128 | /// </summary> | 128 | /// </summary> |
129 | /// <param name="msg">The MSG.</param> | 129 | /// <param name="msg">The MSG.</param> |
130 | public void Write(string msg) | 130 | public void Write(string msg) |
131 | { | 131 | { |
132 | if((m_Target & LogTargets.Null) != 0) | 132 | if((m_Target & LogTargets.Null) != 0) |
133 | { | 133 | { |
134 | return; | 134 | return; |
135 | } | 135 | } |
136 | 136 | ||
137 | if((m_Target & LogTargets.Console) != 0) | 137 | if((m_Target & LogTargets.Console) != 0) |
138 | { | 138 | { |
139 | Console.WriteLine(msg); | 139 | Console.WriteLine(msg); |
140 | } | 140 | } |
141 | if((m_Target & LogTargets.File) != 0 && m_Writer != null) | 141 | if((m_Target & LogTargets.File) != 0 && m_Writer != null) |
142 | { | 142 | { |
143 | m_Writer.WriteLine(msg); | 143 | m_Writer.WriteLine(msg); |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | /// <summary> | 147 | /// <summary> |
148 | /// Writes the specified format. | 148 | /// Writes the specified format. |
149 | /// </summary> | 149 | /// </summary> |
150 | /// <param name="format">The format.</param> | 150 | /// <param name="format">The format.</param> |
151 | /// <param name="args">The args.</param> | 151 | /// <param name="args">The args.</param> |
152 | public void Write(string format, params object[] args) | 152 | public void Write(string format, params object[] args) |
153 | { | 153 | { |
154 | Write(string.Format(format,args)); | 154 | Write(string.Format(format,args)); |
155 | } | 155 | } |
156 | 156 | ||
157 | /// <summary> | 157 | /// <summary> |
158 | /// Writes the specified type. | 158 | /// Writes the specified type. |
159 | /// </summary> | 159 | /// </summary> |
160 | /// <param name="type">The type.</param> | 160 | /// <param name="type">The type.</param> |
161 | /// <param name="format">The format.</param> | 161 | /// <param name="format">The format.</param> |
162 | /// <param name="args">The args.</param> | 162 | /// <param name="args">The args.</param> |
163 | public void Write(LogType type, string format, params object[] args) | 163 | public void Write(LogType type, string format, params object[] args) |
164 | { | 164 | { |
165 | if((m_Target & LogTargets.Null) != 0) | 165 | if((m_Target & LogTargets.Null) != 0) |
166 | { | 166 | { |
167 | return; | 167 | return; |
168 | } | 168 | } |
169 | 169 | ||
170 | string str = ""; | 170 | string str = ""; |
171 | switch(type) | 171 | switch(type) |
172 | { | 172 | { |
173 | case LogType.Info: | 173 | case LogType.Info: |
174 | str = "[I] "; | 174 | str = "[I] "; |
175 | break; | 175 | break; |
176 | case LogType.Warning: | 176 | case LogType.Warning: |
177 | str = "[!] "; | 177 | str = "[!] "; |
178 | break; | 178 | break; |
179 | case LogType.Error: | 179 | case LogType.Error: |
180 | str = "[X] "; | 180 | str = "[X] "; |
181 | break; | 181 | break; |
182 | } | 182 | } |
183 | 183 | ||
184 | Write(str + format,args); | 184 | Write(str + format,args); |
185 | } | 185 | } |
186 | 186 | ||
187 | /// <summary> | 187 | /// <summary> |
188 | /// Writes the exception. | 188 | /// Writes the exception. |
189 | /// </summary> | 189 | /// </summary> |
190 | /// <param name="type">The type.</param> | 190 | /// <param name="type">The type.</param> |
191 | /// <param name="ex">The ex.</param> | 191 | /// <param name="ex">The ex.</param> |
192 | public void WriteException(LogType type, Exception ex) | 192 | public void WriteException(LogType type, Exception ex) |
193 | { | 193 | { |
194 | if(ex != null) | 194 | if(ex != null) |
195 | { | 195 | { |
196 | Write(type, ex.Message); | 196 | Write(type, ex.Message); |
197 | //#if DEBUG | 197 | //#if DEBUG |
198 | m_Writer.WriteLine("Exception @{0} stack trace [[", ex.TargetSite.Name); | 198 | m_Writer.WriteLine("Exception @{0} stack trace [[", ex.TargetSite.Name); |
199 | m_Writer.WriteLine(ex.StackTrace); | 199 | m_Writer.WriteLine(ex.StackTrace); |
200 | m_Writer.WriteLine("]]"); | 200 | m_Writer.WriteLine("]]"); |
201 | //#endif | 201 | //#endif |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | /// <summary> | 205 | /// <summary> |
206 | /// Flushes this instance. | 206 | /// Flushes this instance. |
207 | /// </summary> | 207 | /// </summary> |
208 | public void Flush() | 208 | public void Flush() |
209 | { | 209 | { |
210 | if(m_Writer != null) | 210 | if(m_Writer != null) |
211 | { | 211 | { |
212 | m_Writer.Flush(); | 212 | m_Writer.Flush(); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | 215 | ||
216 | #endregion | 216 | #endregion |
217 | 217 | ||
218 | #region IDisposable Members | 218 | #region IDisposable Members |
219 | |||
220 | /// <summary> | ||
221 | /// Performs application-defined tasks associated with freeing, releasing, or | ||
222 | /// resetting unmanaged resources. | ||
223 | /// </summary> | ||
224 | public void Dispose() | ||
225 | { | ||
226 | Dispose(true); | ||
227 | GC.SuppressFinalize(this); | ||
228 | } | ||
229 | 219 | ||
230 | /// <summary> | 220 | /// <summary> |
231 | /// Dispose objects | 221 | /// Performs application-defined tasks associated with freeing, releasing, or |
232 | /// </summary> | 222 | /// resetting unmanaged resources. |
233 | /// <param name="disposing"> | 223 | /// </summary> |
234 | /// If true, it will dispose close the handle | 224 | public void Dispose() |
235 | /// </param> | 225 | { |
236 | /// <remarks> | 226 | Dispose(true); |
237 | /// Will dispose managed and unmanaged resources. | 227 | GC.SuppressFinalize(this); |
238 | /// </remarks> | 228 | } |
239 | protected virtual void Dispose(bool disposing) | ||
240 | { | ||
241 | if (!this.disposed) | ||
242 | { | ||
243 | if (disposing) | ||
244 | { | ||
245 | if (m_Writer != null) | ||
246 | { | ||
247 | m_Writer.Close(); | ||
248 | m_Writer = null; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | this.disposed = true; | ||
253 | } | ||
254 | 229 | ||
255 | /// <summary> | 230 | /// <summary> |
256 | /// | 231 | /// Dispose objects |
257 | /// </summary> | 232 | /// </summary> |
258 | ~Log() | 233 | /// <param name="disposing"> |
259 | { | 234 | /// If true, it will dispose close the handle |
260 | this.Dispose(false); | 235 | /// </param> |
261 | } | 236 | /// <remarks> |
237 | /// Will dispose managed and unmanaged resources. | ||
238 | /// </remarks> | ||
239 | protected virtual void Dispose(bool disposing) | ||
240 | { | ||
241 | if (!this.disposed) | ||
242 | { | ||
243 | if (disposing) | ||
244 | { | ||
245 | if (m_Writer != null) | ||
246 | { | ||
247 | m_Writer.Close(); | ||
248 | m_Writer = null; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | this.disposed = true; | ||
253 | } | ||
262 | 254 | ||
263 | /// <summary> | 255 | /// <summary> |
264 | /// Closes and destroys this object | 256 | /// |
265 | /// </summary> | 257 | /// </summary> |
266 | /// <remarks> | 258 | ~Log() |
267 | /// Same as Dispose(true) | 259 | { |
268 | /// </remarks> | 260 | this.Dispose(false); |
269 | public void Close() | 261 | } |
270 | { | 262 | |
271 | Dispose(); | 263 | /// <summary> |
272 | } | 264 | /// Closes and destroys this object |
265 | /// </summary> | ||
266 | /// <remarks> | ||
267 | /// Same as Dispose(true) | ||
268 | /// </remarks> | ||
269 | public void Close() | ||
270 | { | ||
271 | Dispose(); | ||
272 | } | ||
273 | 273 | ||
274 | #endregion | 274 | #endregion |
275 | } | 275 | } |
276 | } | 276 | } |