设置是否发送errorlogs(true发送,false不发送)

来源:互联网 发布:linux怎么做脚本 编辑:程序博客网 时间:2024/06/06 07:24

using System;
using System.Web;
using System.Xml;
using System.Web.Caching;

namespace Baolee.GeneralMethod
{
 /// <summary>
 /// ProgSetting 的摘要说明。
 /// </summary>
 public class ProgSetting
 {
  /// <summary>
  /// 构造函数
  /// </summary>
  public ProgSetting()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  /// <summary>
  /// 是否调试,即 Message.SendDebug 方法是否输出记录
  /// </summary>
  public static bool IsDebug
  {
   get
   {
    Cache cache = HttpContext.Current.Cache;
    if (cache["IsDebug"] == null)
    {
     cache.Insert("IsDebug", GetNode("//AppSetting/Debug"), new CacheDependency(SettingFilePath));
    }
    try
    {
     return CheckData.ToBool(cache["IsDebug"]);
    }
    catch
    {
     return false;
    }
   }
  }
  /// <summary>
  ///
  /// </summary>
  private static string SettingFilePath
  {
   get
   {
    return (PublicConst.RootPath + "AppSetting.xml");
   }
  }
  /// <summary>
  ///
  /// </summary>
  /// <param name="xPath"></param>
  /// <returns></returns>
  private static string GetNode(string xPath)
  {
   XmlDocument document = new XmlDocument();
   try
   {
    document.Load(SettingFilePath);
    return document.DocumentElement.SelectSingleNode(xPath).InnerText;
   }
   catch
   {
    return "";
   }
  }

 

AppSetting.xml 

<?xml version="1.0" encoding="GB2312" standalone="yes"?>
<AppSetting>
  <Debug>True</Debug>
</AppSetting>

 

 

 

 

 }
}