zoukankan      html  css  js  c++  java
  • ConfigurationSection自定义配置的使用

    1、web.config配置文件

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
          <section name="log" type="Xys.PetShop.Framework.Configuration.LogConfigurationSetion,Xys.PetShop.Framework"/>
        </configSections>
      <log>
        <filelog path="c:/file.txt" ></filelog>
      </log>
    </configuration>

    2、Xys.PetShop.Framework.Configuration.LogConfigurationSetion必须继承System.Configuration.ConfigurationSection,

        public class LogElement:System.Configuration.ConfigurationElement
        {
            [ConfigurationProperty("path")]
            public string Path
            {
                get { return this["path"] as string; }
                set { this["path"] = value; }
            }
        }

        public class LogConfigurationSetion : ConfigurationSection
        {
            [ConfigurationProperty("filelog")]
            public LogElement FileLog
            {
                get { return this["filelog"] as LogElement; }
                set { this["filelog"] = value; }
            }
        }

    调用

              LogConfigurationSetion config = (LogConfigurationSetion)ConfigurationManager.GetSection("log");
               System.Console.WriteLine(config.FileLog.Path);

  • 相关阅读:
    Django视图
    Django路由系统
    Django概述,配置文件,web框架本质,Django框架
    Mysql
    R语言之常用函数
    从PCA、PLS-DA、OPLS-DA学习线性代数和矩阵
    算法第一关
    别人处理二代测序的流程
    reportlab包使用指南
    Python 文本(txt) 转换成 EXCEL(xls)
  • 原文地址:https://www.cnblogs.com/50614090/p/2184162.html
Copyright © 2011-2022 走看看