当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationManager.LoadXmlConfig方法代码示例

本文整理汇总了C#中ConfigurationManager.LoadXmlConfig方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationManager.LoadXmlConfig方法的具体用法?C# ConfigurationManager.LoadXmlConfig怎么用?C# ConfigurationManager.LoadXmlConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigurationManager的用法示例。


在下文中一共展示了ConfigurationManager.LoadXmlConfig方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

		public static int Main (string[] args)
		{
			// Load the configuration file stored in the
			// executable's resources.
			configmanager = new ConfigurationManager (
				typeof(MainClass).Assembly,
				"ConfigurationManager.xml");

			configmanager.LoadCommandLineArgs (args);

			// Show the help and exit.
			if ((bool)configmanager ["help"] || (bool)configmanager ["?"]) {
				ShowHelp ();
				return 0;
			}

			// Show the version and exit.
			if ((bool)configmanager ["version"]) {
				ShowVersion ();
				return 0;
			}

			string config = (string) configmanager ["config"];

			if (config == null) {
				Console.WriteLine ("You must pass /config=<filename> option. See 'help' for more info");
				return 1;
			}


			try {
				string config_file = (string)configmanager ["configfile"];
				if (config_file != null) configmanager.LoadXmlConfig (config_file);
			} catch (ApplicationException e) {
				Console.WriteLine (e.Message);
				return 1;
			} catch (System.Xml.XmlException e) {
				Console.WriteLine ("Error reading XML configuration: {0}", e.Message);
				return 1;
			}

			try {
				string log_level = (string) configmanager ["loglevels"];

				if (log_level != null) 
					Logger.Level = (LogLevel) Enum.Parse (typeof(LogLevel), log_level);
			} catch {
				Console.WriteLine ("Failed to parse log levels.");
				Console.WriteLine ("Using default levels: {0}", Logger.Level);
			}

			// Enable console logging during Main ().
			Logger.WriteToConsole = true;

			try {
				string log_file = (string) configmanager ["logfile"];

				if (log_file != null) Logger.Open (log_file);
			} catch (Exception e) {
				Logger.Write (LogLevel.Error, "Error opening log file: {0}", e.Message);
				Logger.Write (LogLevel.Error,"Events will not be logged.");
			}

			Logger.Write (LogLevel.Debug,
				Assembly.GetExecutingAssembly ().GetName ().Name);

			bool auto_map = false; //(bool) configmanager ["automappaths"];

			string applications = (string) configmanager ["applications"];
			string app_config_file;
			string app_config_dir;

			try {
				app_config_file = (string) configmanager ["appconfigfile"];
				app_config_dir = (string) configmanager ["appconfigdir"];
			} catch (ApplicationException e) {
				Logger.Write (LogLevel.Error, e.Message);
				return 1;
			}

//			server.MaxConnections = (ushort)
//			                        configmanager ["maxconns"];
//			server.MaxRequests = (ushort)
//			                     configmanager ["maxreqs"];
//			server.MultiplexConnections = (bool)
//			                              configmanager ["multiplex"];

//			Logger.Write (LogLevel.Debug, "Max connections: {0}",
//				server.MaxConnections);
//			Logger.Write (LogLevel.Debug, "Max requests: {0}",
//				server.MaxRequests);
//			Logger.Write (LogLevel.Debug, "Multiplex connections: {0}",
//				server.MultiplexConnections);

			bool stopable = (bool)configmanager ["stopable"];
			Logger.WriteToConsole = (bool)configmanager ["printlog"];

			List<ConfigInfo> serverConfigs = ConfigUtils.GetConfigsFromFile (config, "server", typeof(AppServerConfig));
			if (serverConfigs.Count != 1) {
				if (serverConfigs.Count == 0) {
//.........这里部分代码省略.........
开发者ID:qinfengzhu,项目名称:HyperFastCgi,代码行数:101,代码来源:Main.cs


注:本文中的ConfigurationManager.LoadXmlConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。