TraceConfigurationHandler.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // System.Web.Configuation.TraceConfigurationHandler
  3. //
  4. // Author(s):
  5. // Jackson Harper ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Web;
  11. using System.Xml;
  12. using System.Configuration;
  13. namespace System.Web.Configuration {
  14. internal class TraceConfigurationHandler : IConfigurationSectionHandler {
  15. public object Create (object parent, object context, XmlNode section)
  16. {
  17. TraceConfig config = new TraceConfig ();
  18. string enabled_str = AttValue ("enabled", section);
  19. if (enabled_str != null) {
  20. try {
  21. config.Enabled = Boolean.Parse (enabled_str);
  22. } catch {
  23. ThrowException ("The 'enabled' attribute is case sensitive" +
  24. " and must be set to 'true' or 'false'.", section);
  25. }
  26. }
  27. string local_str = AttValue ("localOnly", section);
  28. if (local_str != null) {
  29. try {
  30. config.LocalOnly = Boolean.Parse (local_str);
  31. } catch {
  32. ThrowException ("The 'localOnly' attribute is case sensitive" +
  33. " and must be set to 'true' or 'false'.", section);
  34. }
  35. }
  36. string page_str = AttValue ("pageOutput", section);
  37. if (page_str != null) {
  38. try {
  39. config.PageOutput = Boolean.Parse (page_str);
  40. } catch {
  41. ThrowException ("The 'pageOutput' attribute is case sensitive" +
  42. " and must be set to 'true' or 'false'.", section);
  43. }
  44. }
  45. string limit_str = AttValue ("requestLimit", section);
  46. if (limit_str != null) {
  47. try {
  48. config.RequestLimit = Int32.Parse (limit_str);
  49. } catch {
  50. ThrowException ("The 'requestLimit' attribute must be an integer value.",
  51. section);
  52. }
  53. }
  54. string trace_str = AttValue ("traceMode", section);
  55. if (trace_str != null) {
  56. try {
  57. config.TraceMode = (TraceMode) Enum.Parse (typeof (TraceMode), trace_str);
  58. } catch {
  59. ThrowException ("The 'traceMode' attribute is case sensitive and must be" +
  60. " one of the following values: SortByTime, SortByCategory.",
  61. section);
  62. }
  63. }
  64. return config;
  65. }
  66. // A few methods to save some typing
  67. static string AttValue (string name, XmlNode node)
  68. {
  69. return HandlersUtil.ExtractAttributeValue (name, node, true);
  70. }
  71. static void ThrowException (string message, XmlNode node)
  72. {
  73. HandlersUtil.ThrowException (message, node);
  74. }
  75. }
  76. }