~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/NU-SimiasAspService/.svn/text-base/Tracing.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 |
4
 
 | Copyright (c) 2007 Novell, Inc.
5
 
 | All Rights Reserved.
6
 
 |
7
 
 | This program is free software; you can redistribute it and/or
8
 
 | modify it under the terms of version 2 of the GNU General Public License as
9
 
 | published by the Free Software Foundation.
10
 
 |
11
 
 | This program is distributed in the hope that it will be useful,
12
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 | GNU General Public License for more details.
15
 
 |
16
 
 | You should have received a copy of the GNU General Public License
17
 
 | along with this program; if not, contact Novell, Inc.
18
 
 |
19
 
 | To contact Novell about this file by physical or electronic mail,
20
 
 | you may find current contact information at www.novell.com 
21
 
 |
22
 
 | Authors:
23
 
 | Gonzalo Paniagua Javier (gonzalo@ximian.com)
24
 
 |***************************************************************************/
25
 
 
26
 
 
27
 
using System;
28
 
using System.Collections;
29
 
using System.Diagnostics;
30
 
 
31
 
namespace Mono.ASPNET
32
 
{
33
 
        internal class WebTrace
34
 
        {
35
 
                static Stack ctxStack;
36
 
                static bool trace;
37
 
                static int indentation; // Number of \t
38
 
 
39
 
                static WebTrace ()
40
 
                {
41
 
                        ctxStack = new Stack ();
42
 
                }
43
 
 
44
 
                [Conditional("WEBTRACE")]
45
 
                static public void PushContext (string context)
46
 
                {
47
 
                        ctxStack.Push (context);
48
 
                        indentation++;
49
 
                }
50
 
                
51
 
                [Conditional("WEBTRACE")]
52
 
                static public void PopContext ()
53
 
                {
54
 
                        if (ctxStack.Count == 0)
55
 
                                return;
56
 
 
57
 
                        indentation--;
58
 
                        ctxStack.Pop ();
59
 
                }
60
 
 
61
 
                static public string Context
62
 
                {
63
 
                        get {
64
 
                                if (ctxStack.Count == 0)
65
 
                                        return String.Empty;
66
 
 
67
 
                                return (string) ctxStack.Peek ();
68
 
                        }
69
 
                }
70
 
 
71
 
                static public bool StackTrace
72
 
                {
73
 
                        get { return trace; }
74
 
 
75
 
                        set { trace = value; }
76
 
                }
77
 
                
78
 
                [Conditional("WEBTRACE")]
79
 
                static public void WriteLine (string msg)
80
 
                {
81
 
                        Console.WriteLine (Format (msg));
82
 
                }
83
 
 
84
 
                [Conditional("WEBTRACE")]
85
 
                static public void WriteLine (string msg, object arg)
86
 
                {
87
 
                        Console.WriteLine (Format (String.Format (msg, arg)));
88
 
                }
89
 
 
90
 
                [Conditional("WEBTRACE")]
91
 
                static public void WriteLine (string msg, object arg1, object arg2)
92
 
                {
93
 
                        Console.WriteLine (Format (String.Format (msg, arg1, arg2)));
94
 
                }
95
 
 
96
 
                [Conditional("WEBTRACE")]
97
 
                static public void WriteLine (string msg, object arg1, object arg2, object arg3)
98
 
                {
99
 
                        Console.WriteLine (Format (String.Format (msg, arg1, arg2, arg3)));
100
 
                }
101
 
 
102
 
                [Conditional("WEBTRACE")]
103
 
                static public void WriteLine (string msg, params object [] args)
104
 
                {
105
 
                        Console.WriteLine (Format (String.Format (msg, args)));
106
 
                }
107
 
 
108
 
                static string Tabs
109
 
                {
110
 
                        get {
111
 
                                if (indentation == 0)
112
 
                                        return String.Empty;
113
 
 
114
 
                                return new String ('\t', indentation);
115
 
                        }
116
 
                }
117
 
 
118
 
                static string Format (string msg)
119
 
                {
120
 
                        string ctx = Tabs + Context;
121
 
                        if (ctx.Length != 0)
122
 
                                ctx += ": ";
123
 
                        
124
 
                        string result = ctx + msg;
125
 
                        if (trace)
126
 
                                result += "\n" + Environment.StackTrace;
127
 
 
128
 
                        return result;
129
 
                }
130
 
        }
131
 
}
132