TraceManager.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // System.Web.TraceManager
  3. //
  4. // Author(s):
  5. // Jackson Harper ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.Web.Configuration;
  32. namespace System.Web {
  33. internal class TraceManager {
  34. private static string traceConfigPath = "system.web/trace";
  35. private bool enabled = false;
  36. private bool local_only = true;
  37. private bool page_output = false;
  38. private TraceMode mode;
  39. private int request_limit = 10;
  40. private int cur_item;
  41. private TraceData[] data;
  42. public TraceManager ()
  43. {
  44. #if NET_2_0
  45. TraceSection config = WebConfigurationManager.GetSection ("system.web/trace") as TraceSection;
  46. if (config == null)
  47. config = new TraceSection ();
  48. #else
  49. TraceConfig config = (TraceConfig) HttpContext.GetAppConfig (traceConfigPath);
  50. #endif
  51. if (config == null)
  52. return;
  53. enabled = config.Enabled;
  54. local_only = config.LocalOnly;
  55. page_output = config.PageOutput;
  56. #if NET_2_0
  57. if (config.TraceMode == TraceDisplayMode.SortByTime)
  58. mode = TraceMode.SortByTime;
  59. else
  60. mode = TraceMode.SortByCategory;
  61. #else
  62. mode = config.TraceMode;
  63. #endif
  64. request_limit = config.RequestLimit;
  65. }
  66. public bool Enabled {
  67. get { return enabled; }
  68. set { enabled = value; }
  69. }
  70. public bool LocalOnly {
  71. get { return local_only; }
  72. set { local_only = value; }
  73. }
  74. public bool PageOutput {
  75. get { return page_output; }
  76. set { page_output = value; }
  77. }
  78. public int RequestLimit {
  79. get { return request_limit; }
  80. set {
  81. if (request_limit == value)
  82. return;
  83. TraceData[] swap = new TraceData [value];
  84. Array.Copy (data, swap, (cur_item > value ? value : cur_item));
  85. if (cur_item > value)
  86. cur_item = value;
  87. request_limit = value;
  88. }
  89. }
  90. public TraceMode TraceMode {
  91. get { return mode; }
  92. set { mode = value; }
  93. }
  94. public TraceData[] TraceData {
  95. get { return data; }
  96. }
  97. public void AddTraceData (TraceData item)
  98. {
  99. if (data == null)
  100. data = new TraceData [request_limit];
  101. if (cur_item == request_limit)
  102. return;
  103. data [cur_item++] = item;
  104. }
  105. public void Clear ()
  106. {
  107. if (data == null)
  108. return;
  109. Array.Clear (data, 0, data.Length);
  110. cur_item = 0;
  111. }
  112. public int ItemCount {
  113. get { return cur_item; }
  114. }
  115. }
  116. }