2 // System.Web.Util.WebTrace
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002 Ximian, Inc (http://www.ximian.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.
31 using System
.Collections
;
32 using System
.Diagnostics
;
34 namespace System
.Web
.Util
36 internal class WebTrace
38 static Stack ctxStack
;
43 ctxStack
= new Stack ();
46 [Conditional("WEBTRACE")]
47 static public void PushContext (string context
)
49 ctxStack
.Push (context
);
53 [Conditional("WEBTRACE")]
54 static public void PopContext ()
56 if (ctxStack
.Count
== 0)
63 static public string Context
66 if (ctxStack
.Count
== 0)
69 return (string) ctxStack
.Peek ();
73 static public bool StackTrace
77 set { trace = value; }
80 [Conditional("WEBTRACE")]
81 static public void WriteLine (string msg
)
83 Trace
.WriteLine (Format (msg
));
86 [Conditional("WEBTRACE")]
87 static public void WriteLine (string msg
, object arg
)
89 Trace
.WriteLine (Format (String
.Format (msg
, arg
)));
92 [Conditional("WEBTRACE")]
93 static public void WriteLine (string msg
, object arg1
, object arg2
)
95 Trace
.WriteLine (Format (String
.Format (msg
, arg1
, arg2
)));
98 [Conditional("WEBTRACE")]
99 static public void WriteLine (string msg
, object arg1
, object arg2
, object arg3
)
101 Trace
.WriteLine (Format (String
.Format (msg
, arg1
, arg2
, arg3
)));
104 [Conditional("WEBTRACE")]
105 static public void WriteLine (string msg
, params object [] args
)
107 Trace
.WriteLine (Format (String
.Format (msg
, args
)));
110 static string Format (string msg
)
113 return String
.Format ("{0}: {1}\n{2}", Context
, msg
, Environment
.StackTrace
);
115 return String
.Format ("{0}: {1}", Context
, msg
);