• 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);

  • 相关阅读:
    [NOIP2020]T2字符串匹配
    【CSGRound2】逐梦者的初心(洛谷11月月赛 II & CSG Round 2 T3)
    【CF1225E Rock Is Push】推岩石
    [HAOI2016]食物链
    求先序排列
    图书管理员
    合并果子
    联合权值
    和为0的4个值
    玩具谜题
  • 原文地址:https://www.cnblogs.com/50614090/p/2184162.html
Copyright © 2020-2023  润新知