本文整理汇总了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) {
//.........这里部分代码省略.........