2 // System.Web.TraceManager
5 // Jackson Harper (jackson@ximian.com)
7 // (C) 2004 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;
36 namespace System.Web {
38 internal class TraceManager {
40 static string traceConfigPath = "system.web/trace";
43 bool local_only = true;
44 bool page_output = false;
46 int request_limit = 10;
51 Exception initialException;
53 public TraceManager ()
57 mode = TraceMode.SortByTime;
58 TraceSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/trace") as TraceSection;
60 config = new TraceSection ();
62 TraceConfig config = (TraceConfig) HttpContext.GetAppConfig (traceConfigPath);
68 enabled = config.Enabled;
69 local_only = config.LocalOnly;
70 page_output = config.PageOutput;
72 if (config.TraceMode == TraceDisplayMode.SortByTime)
73 mode = TraceMode.SortByTime;
75 mode = TraceMode.SortByCategory;
77 mode = config.TraceMode;
79 request_limit = config.RequestLimit;
80 } catch (Exception ex) {
81 initialException = ex;
85 public bool HasException {
86 get { return initialException != null; }
89 public Exception InitialException {
90 get { return initialException; }
94 get { return enabled; }
95 set { enabled = value; }
98 public bool LocalOnly {
99 get { return local_only; }
100 set { local_only = value; }
103 public bool PageOutput {
104 get { return page_output; }
105 set { page_output = value; }
108 public int RequestLimit {
109 get { return request_limit; }
111 if (request_limit == value)
113 TraceData[] swap = new TraceData [value];
114 Array.Copy (data, swap, (cur_item > value ? value : cur_item));
115 if (cur_item > value)
117 request_limit = value;
121 public TraceMode TraceMode {
123 set { mode = value; }
126 public TraceData[] TraceData {
130 public void AddTraceData (TraceData item)
133 data = new TraceData [request_limit];
134 if (cur_item == request_limit)
136 data [cur_item++] = item;
144 Array.Clear (data, 0, data.Length);
148 public int ItemCount {
149 get { return cur_item; }