zoukankan      html  css  js  c++  java
  • c# 配置文件获取类

    public class ConfigHelper
    {
    /// <summary>
    /// jailall.sun 写错误日志
    /// </summary>
    /// <param name="message"></param>
    public static void ErrorLog(string methodName, Exception ex)
    {
    string path = Application.StartupPath + "\errorLog\" + DateTime.Now.ToString("yyyMMdd");
    FileHelper.AppendText(path, "--------------" + methodName + "--------------");
    FileHelper.AppendText(path, "message:" + ex.Message);
    FileHelper.AppendText(path, "Source:" + ex.Source);
    FileHelper.AppendText(path, "StackTrace:" + ex.StackTrace);
    FileHelper.AppendText(path, "TargetSite:" + ex.TargetSite.ToString());
    FileHelper.AppendText(path, "");
    }
    /// <summary>
    /// 获取配制信息
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    //public static string GetAppstring(string key)
    //{
    // try
    // {
    // string WinConfig = Application.StartupPath + "\Web.config";
    // XElement wc = XElement.Load(WinConfig);
    // var add = wc.Descendants("add").ToList().Where(c => c.Attribute("key").Value == key).First();
    // string str = add.Attribute("value").Value;
    // return str;
    // }
    // catch (Exception ex)
    // {
    // return ex.Message;
    // }
    //}
    /// <summary>
    /// 获取配置值
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static string GetConfigStr(string key)
    {
    try
    {
    return ConfigurationManager.AppSettings[key];
    }
    catch (Exception ex)
    {
    return ex.Message;
    }
    }
    }

  • 相关阅读:
    WMI介绍
    进程间通信
    回调函数(C/C++)
    漏洞名词介绍
    MD5 详解
    jQuery插件的写法
    node爬虫
    nodejs应用:文件上传
    node开发备注
    node生成自定义命令(yargs/commander)
  • 原文地址:https://www.cnblogs.com/2260827114com/p/6479874.html
Copyright © 2011-2022 走看看