2 // System.Web.TraceContext
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 // Jackson Harper (jackson@ximian.com)
8 // (C) 2002 2003, Patrik Torstensson
9 // (C) 2003 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
37 using System.Web.UI.WebControls;
39 namespace System.Web {
40 public sealed class TraceContext {
47 Hashtable view_states;
50 public TraceContext (HttpContext Context)
55 internal bool HaveTrace {
61 public bool IsEnabled {
64 return HttpRuntime.TraceManager.Enabled;
69 if (value && data == null)
70 data = new TraceData ();
76 public TraceMode TraceMode {
85 public void Warn(string msg)
87 Write (String.Empty, msg, null, true);
90 public void Warn(string category, string msg)
92 Write (category, msg, null, true);
95 public void Warn (string category, string msg, Exception error)
97 Write (category, msg, error, true);
100 public void Write (string msg)
102 Write (String.Empty, msg, null, false);
105 public void Write (string category, string msg)
107 Write (category, msg, null, false);
110 public void Write (string category, string msg, Exception error)
112 Write (category, msg, error, false);
115 void Write (string category, string msg, Exception error, bool Warning)
120 data = new TraceData ();
121 data.Write (category, msg, error, Warning);
124 internal void SaveData ()
127 data = new TraceData ();
128 SetRequestDetails ();
129 if (_Context.Handler is Page)
130 data.AddControlTree ((Page) _Context.Handler, view_states, sizes);
135 HttpRuntime.TraceManager.AddTraceData (data);
139 internal void SaveViewState (Control ctrl, object vs)
141 if (view_states == null)
142 view_states = new Hashtable ();
144 view_states [ctrl] = vs;
147 internal void SaveSize (Control ctrl, int size)
150 sizes = new Hashtable ();
155 internal void Render (HtmlTextWriter output)
159 data.Render (output);
162 void SetRequestDetails ()
164 data.RequestPath = _Context.Request.FilePath;
165 data.SessionID = (_Context.Session != null ? _Context.Session.SessionID : String.Empty);
166 data.RequestType = _Context.Request.RequestType;
167 data.RequestTime = _Context.Timestamp;
168 data.StatusCode = _Context.Response.StatusCode;
169 data.RequestEncoding = _Context.Request.ContentEncoding;
170 data.ResponseEncoding = _Context.Response.ContentEncoding;
175 foreach (string key in _Context.Request.Cookies.Keys)
176 data.AddCookie (key, _Context.Request.Cookies [key].Value);
181 foreach (string key in _Context.Request.Headers.Keys)
182 data.AddHeader (key, _Context.Request.Headers [key]);
185 void AddServerVars ()
187 foreach (string key in _Context.Request.ServerVariables)
188 data.AddServerVar (key, _Context.Request.ServerVariables [key]);