private static string PeriodRepresentation(LoggingRolloverPeriod period)
        {
            switch (period)
            {
            case LoggingRolloverPeriod.MaxSize:
                return("max_size");

            default:
                return(Enum.GetName(typeof(LoggingRolloverPeriod), period).ToLower());
            }
        }
Example #2
0
 /// <summary>
 /// 新建网站站点
 /// </summary>
 /// <param name="siteName">站点名</param>
 /// <param name="ip">ip 空字符串则为则直接默认 * </param>
 /// <param name="port">端口</param>
 /// <param name="hostName">主机名</param>
 /// <param name="physicalPath">物理路径</param>
 /// <param name="queueLength">队列长度</param>
 /// <param name="maxProcesses">最大工作进程数</param>
 /// <param name="netVersion">.net clr版本</param>
 /// <param name="appPoolPipelineMode">应用程序池托管管道模式</param>
 /// <param name="rapidFailProtectionMaxCrashes">最大故障数</param>
 /// <param name="logDirectoryPath">IIS日志目录路径</param>
 /// <param name="logFormat">日志格式</param>
 /// <param name="logExtFileFlags">日志存储的字段</param>
 /// <param name="loggingRolloverPeriod">日志的存储计划</param>
 /// <param name="logTruncateSize">日志单个文件最大大小(字节)</param>
 public static void CreateSite(string siteName, string ip, int port, string hostName, string physicalPath, long queueLength, long maxProcesses, NetVersion netVersion, ManagedPipelineMode appPoolPipelineMode, long rapidFailProtectionMaxCrashes, string logDirectoryPath, LogFormat logFormat, LogExtFileFlags logExtFileFlags, LoggingRolloverPeriod loggingRolloverPeriod, long logTruncateSize)
 {
     ip = String.IsNullOrWhiteSpace(ip) ? "*" : ip;
     CreateSite(siteName, $"{ip}:{port}:{hostName}", physicalPath, queueLength, maxProcesses, netVersion, appPoolPipelineMode, rapidFailProtectionMaxCrashes, logDirectoryPath, logFormat, logExtFileFlags, loggingRolloverPeriod, logTruncateSize);
 }
Example #3
0
        /// <summary>
        /// 新建网站站点
        /// </summary>
        /// <param name="siteName">站点名</param>
        /// <param name="protocol">站点协议,如:http</param>
        /// <param name="bindingInformation">绑定的相关信息 "*:&lt;port&gt;:&lt;hostname&gt;" <example>"*:80:myhost.com"</example></param>
        /// <param name="physicalPath">物理路径</param>
        /// <param name="createAppPool">是否新建应用程序池</param>
        /// <param name="appPoolName">应用程序池名称</param>
        /// <param name="queueLength">队列长度</param>
        /// <param name="identityType">进程模型标识</param>
        /// <param name="idleTimeout">闲着超时时间(秒)</param>
        /// <param name="appPoolUserName">应用程序池特殊用户的用户名</param>
        /// <param name="appPoolPassword">应用程序池特殊用户的密码</param>
        /// <param name="maxProcesses">最大工作进程数</param>
        /// <param name="appPoolPipelineMode">应用程序池托管管道模式</param>
        /// <param name="managedRuntimeVersion">.net clr版本</param>
        /// <param name="rapidFailProtectionMaxCrashes">最大故障数</param>
        /// <param name="logDirectoryPath">IIS日志目录路径</param>
        /// <param name="logFormat">日志格式</param>
        /// <param name="logExtFileFlags">日志存储的字段</param>
        /// <param name="loggingRolloverPeriod">日志的存储计划</param>
        /// <param name="logTruncateSize">日志单个文件最大大小(MB) 最小为1MB<paramref name="loggingRolloverPeriod">LoggingRolloverPeriod.MaxSize</paramref> </param>
        public static void CreateSite(string siteName, string protocol, string bindingInformation, string physicalPath, bool createAppPool, string appPoolName, long queueLength, ProcessModelIdentityType identityType, long idleTimeout, string appPoolUserName, string appPoolPassword, long maxProcesses, ManagedPipelineMode appPoolPipelineMode, string managedRuntimeVersion, long rapidFailProtectionMaxCrashes, string logDirectoryPath, LogFormat logFormat, LogExtFileFlags logExtFileFlags, LoggingRolloverPeriod loggingRolloverPeriod, long logTruncateSize)
        {
            if (logTruncateSize < 1)
            {
                throw new Exception("日志单个文件最大大小的值必须>=1MB");
            }
            using (var mgr = new ServerManager(ApplicationHostConfigurationPath))
            {
                var site = mgr.Sites[siteName];
                if (site == null)
                {
                    site = mgr.Sites.Add(siteName, protocol, bindingInformation, physicalPath);
                    site.LogFile.Enabled         = true;
                    site.ServerAutoStart         = true;
                    site.LogFile.Directory       = logDirectoryPath;
                    site.LogFile.Period          = loggingRolloverPeriod;
                    site.LogFile.LogExtFileFlags = logExtFileFlags;
                    site.LogFile.TruncateSize    = logTruncateSize * 1024 * 1024;
                    site.LogFile.LogFormat       = logFormat;

                    if (createAppPool)
                    {
                        var pool = mgr.ApplicationPools.Add(siteName);
                        pool.Name = appPoolName;
                        pool.ManagedRuntimeVersion     = managedRuntimeVersion;
                        pool.QueueLength               = queueLength;
                        pool.ProcessModel.MaxProcesses = maxProcesses;
                        if (pool.ProcessModel.IdentityType != identityType)
                        {
                            pool.ProcessModel.IdentityType = identityType;
                        }
                        pool.ProcessModel.IdleTimeout = TimeSpan.FromSeconds(idleTimeout);
                        if (!String.IsNullOrEmpty(appPoolUserName))
                        {
                            pool.ProcessModel.UserName = appPoolUserName;
                            pool.ProcessModel.Password = appPoolPassword;
                        }
                        if (pool.ManagedPipelineMode != appPoolPipelineMode)
                        {
                            pool.ManagedPipelineMode = appPoolPipelineMode;
                        }
                        pool.Failure.RapidFailProtectionMaxCrashes = rapidFailProtectionMaxCrashes;
                        mgr.Sites[siteName].Applications[0].ApplicationPoolName = pool.Name;
                    }
                    mgr.CommitChanges();
                }
                else
                {
                    throw new Exception($"the web site:{siteName} is already exist");
                }
            }
        }
Example #4
0
        /// <summary>
        /// 新建网站站点
        /// </summary>
        /// <param name="siteName">站点名</param>
        /// <param name="bindingInfo">绑定的相关信息 "*:&lt;port&gt;:&lt;hostname&gt;" <example>"*:80:myhost.com"</example></param>
        /// <param name="physicalPath">物理路径</param>
        /// <param name="queueLength">队列长度</param>
        /// <param name="maxProcesses">最大工作进程数</param>
        /// <param name="netVersion">.net clr版本</param>
        /// <param name="appPoolPipelineMode">应用程序池托管管道模式</param>
        /// <param name="rapidFailProtectionMaxCrashes">最大故障数</param>
        /// <param name="logDirectoryPath">IIS日志目录路径</param>
        /// <param name="logFormat">日志格式</param>
        /// <param name="logExtFileFlags">日志存储的字段</param>
        /// <param name="loggingRolloverPeriod">日志的存储计划</param>
        /// <param name="logTruncateSize">日志单个文件最大大小(字节)</param>
        public static void CreateSite(string siteName, string bindingInfo, string physicalPath, long queueLength, long maxProcesses, NetVersion netVersion, ManagedPipelineMode appPoolPipelineMode, long rapidFailProtectionMaxCrashes, string logDirectoryPath, LogFormat logFormat, LogExtFileFlags logExtFileFlags, LoggingRolloverPeriod loggingRolloverPeriod, long logTruncateSize)
        {
            var managedRuntimeVersion = netVersion == NetVersion.V2 ? NetVersion2 : NetVersion4;

            CreateSite(siteName, "http", bindingInfo, physicalPath, true, siteName, queueLength, ProcessModelIdentityType.ApplicationPoolIdentity, 120, null, null, maxProcesses, appPoolPipelineMode, managedRuntimeVersion, rapidFailProtectionMaxCrashes, logDirectoryPath, logFormat, logExtFileFlags, loggingRolloverPeriod, logTruncateSize);
        }