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 = false;
47 public TraceContext(HttpContext Context) {
\r
53 internal bool HaveTrace {
59 public bool IsEnabled {
\r
65 if (value && data == null)
\r
66 data = new TraceData ();
\r
72 public TraceMode TraceMode {
\r
82 public void Warn(string msg) {
\r
83 Write(String.Empty, msg, null, true);
\r
86 public void Warn(string category, string msg) {
\r
87 Write(category, msg, null, true);
\r
90 public void Warn(string category, string msg, Exception error) {
\r
91 Write(category, msg, error, true);
\r
94 public void Write(string msg) {
\r
95 Write(String.Empty, msg, null, true);
\r
98 public void Write(string category, string msg) {
\r
99 Write(category, msg, null, false);
\r
102 public void Write(string category, string msg, Exception error) {
\r
103 Write(category, msg, error, false);
\r
106 private void Write(string category, string msg, Exception error, bool Warning) {
\r
110 data = new TraceData ();
\r
111 data.Write (category, msg, error, Warning);
\r
114 internal void SaveData ()
\r
117 data = new TraceData ();
\r
118 SetRequestDetails ();
\r
119 data.AddControlTree ((Page) _Context.Handler);
\r
123 HttpRuntime.TraceManager.AddTraceData (data);
\r
127 internal void Render (HtmlTextWriter output)
\r
131 data.Render (output);
\r
134 private void SetRequestDetails ()
\r
136 data.RequestPath = _Context.Request.FilePath;
\r
137 data.SessionID = (_Context.Session != null ? _Context.Session.SessionID : String.Empty);
\r
138 data.RequestType = _Context.Request.RequestType;
\r
139 data.RequestTime = _Context.Timestamp;
\r
140 data.StatusCode = _Context.Response.StatusCode;
\r
141 data.RequestEncoding = _Context.Request.ContentEncoding;
\r
142 data.ResponseEncoding = _Context.Response.ContentEncoding;
\r
145 private void AddCookies ()
\r
147 foreach (string key in _Context.Request.Cookies.Keys)
\r
148 data.AddCookie (key, _Context.Request.Cookies [key].Value);
\r
151 private void AddHeaders ()
\r
153 foreach (string key in _Context.Request.Headers.Keys)
\r
154 data.AddHeader (key, _Context.Request.Headers [key]);
\r
157 private void AddServerVars ()
\r
159 foreach (string key in _Context.Request.ServerVariables)
\r
160 data.AddServerVar (key, _Context.Request.ServerVariables [key]);
\r