2 // System.Web.TraceContext
\r
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
\r
6 // Jackson Harper (jackson@ximian.com)
\r
8 // (C) 2002 2003, Patrik Torstensson
\r
9 // (C) 2003 Novell, Inc (http://www.novell.com)
\r
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.
35 using System.Web.UI;
\r
36 using System.Web.UI.WebControls;
\r
38 namespace System.Web {
\r
39 public sealed class TraceContext {
\r
40 private HttpContext _Context;
\r
41 private bool _Enabled;
\r
42 private TraceMode _Mode;
\r
43 private TraceData data;
\r
44 private bool data_saved;
\r
45 private bool _haveTrace;
47 public TraceContext(HttpContext Context) {
\r
53 internal bool HaveTrace {
59 public bool IsEnabled {
\r
62 return HttpRuntime.TraceManager.Enabled;
67 if (value && data == null)
\r
68 data = new TraceData ();
\r
74 public TraceMode TraceMode {
\r
84 public void Warn(string msg) {
\r
85 Write(String.Empty, msg, null, true);
\r
88 public void Warn(string category, string msg) {
\r
89 Write(category, msg, null, true);
\r
92 public void Warn(string category, string msg, Exception error) {
\r
93 Write(category, msg, error, true);
\r
96 public void Write(string msg) {
\r
97 Write(String.Empty, msg, null, true);
\r
100 public void Write(string category, string msg) {
\r
101 Write(category, msg, null, false);
\r
104 public void Write(string category, string msg, Exception error) {
\r
105 Write(category, msg, error, false);
\r
108 private void Write(string category, string msg, Exception error, bool Warning) {
\r
112 data = new TraceData ();
\r
113 data.Write (category, msg, error, Warning);
\r
116 internal void SaveData ()
\r
119 data = new TraceData ();
\r
120 SetRequestDetails ();
\r
121 data.AddControlTree ((Page) _Context.Handler);
\r
125 HttpRuntime.TraceManager.AddTraceData (data);
\r
129 internal void Render (HtmlTextWriter output)
\r
133 data.Render (output);
\r
136 private void SetRequestDetails ()
\r
138 data.RequestPath = _Context.Request.FilePath;
\r
139 data.SessionID = (_Context.Session != null ? _Context.Session.SessionID : String.Empty);
\r
140 data.RequestType = _Context.Request.RequestType;
\r
141 data.RequestTime = _Context.Timestamp;
\r
142 data.StatusCode = _Context.Response.StatusCode;
\r
143 data.RequestEncoding = _Context.Request.ContentEncoding;
\r
144 data.ResponseEncoding = _Context.Response.ContentEncoding;
\r
147 private void AddCookies ()
\r
149 foreach (string key in _Context.Request.Cookies.Keys)
\r
150 data.AddCookie (key, _Context.Request.Cookies [key].Value);
\r
153 private void AddHeaders ()
\r
155 foreach (string key in _Context.Request.Headers.Keys)
\r
156 data.AddHeader (key, _Context.Request.Headers [key]);
\r
159 private void AddServerVars ()
\r
161 foreach (string key in _Context.Request.ServerVariables)
\r
162 data.AddServerVar (key, _Context.Request.ServerVariables [key]);
\r