2 // System.Web.TraceManager
5 // Jackson Harper (jackson@ximian.com)
7 // (C) 2004-2009 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Web.Configuration;
38 sealed class TraceManager
41 bool local_only = true;
42 bool page_output = false;
44 int request_limit = 10;
49 Exception initialException;
51 public TraceManager ()
54 mode = TraceMode.SortByTime;
55 TraceSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/trace") as TraceSection;
57 config = new TraceSection ();
62 enabled = config.Enabled;
63 local_only = config.LocalOnly;
64 page_output = config.PageOutput;
65 if (config.TraceMode == TraceDisplayMode.SortByTime)
66 mode = TraceMode.SortByTime;
68 mode = TraceMode.SortByCategory;
69 request_limit = config.RequestLimit;
70 } catch (Exception ex) {
71 initialException = ex;
75 public bool HasException {
76 get { return initialException != null; }
79 public Exception InitialException {
80 get { return initialException; }
84 get { return enabled; }
85 set { enabled = value; }
88 public bool LocalOnly {
89 get { return local_only; }
90 set { local_only = value; }
93 public bool PageOutput {
94 get { return page_output; }
95 set { page_output = value; }
98 public int RequestLimit {
99 get { return request_limit; }
101 if (request_limit == value)
103 TraceData[] swap = new TraceData [value];
104 Array.Copy (data, swap, (cur_item > value ? value : cur_item));
105 if (cur_item > value)
107 request_limit = value;
111 public TraceMode TraceMode {
113 set { mode = value; }
116 public TraceData[] TraceData {
120 public void AddTraceData (TraceData item)
123 data = new TraceData [request_limit];
124 if (cur_item == request_limit)
126 data [cur_item++] = item;
134 Array.Clear (data, 0, data.Length);
138 public int ItemCount {
139 get { return cur_item; }