From 0b960bd689c77622327f69f81ad8e89c411e14d0 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Fri, 29 Dec 2017 10:14:19 -0500 Subject: [PATCH] Fixed logging truncate size support. --- .../LoggingFeature.cs | 26 +++-- .../LoggingPage.Designer.cs | 44 +++++---- JexusManager.Features.Logging/LoggingPage.cs | 97 +++++++++++++------ .../LoggingPage.resx | 3 + .../Services/ConfigurationService.cs | 4 + JexusManager/Properties/AssemblyInfo.cs | 4 +- Microsoft.Web.Administration/CommonHelper.cs | 5 + 7 files changed, 124 insertions(+), 59 deletions(-) diff --git a/JexusManager.Features.Logging/LoggingFeature.cs b/JexusManager.Features.Logging/LoggingFeature.cs index bf126f17..6790ce17 100644 --- a/JexusManager.Features.Logging/LoggingFeature.cs +++ b/JexusManager.Features.Logging/LoggingFeature.cs @@ -96,7 +96,7 @@ public TaskList GetTaskList() public void Load() { var service = (IConfigurationService)GetService(typeof(IConfigurationService)); - var section = service.GetSection("system.applicationHost/log"); + var section = service.GetSection("system.applicationHost/log", null, false); Mode = (long)section.Attributes["centralLogFileMode"].Value; Encoding = (bool)section.Attributes["logInUTF8"].Value ? 0 : 1; @@ -116,7 +116,7 @@ public void Load() } LocalTimeRollover = (bool)element.Attributes["localTimeRollover"].Value; - TruncateSize = (long)element.Attributes["truncateSize"].Value; + TruncateSizeString = element.Attributes["truncateSize"].Value.ToString(); Period = (long)element.Attributes["period"].Value; } else @@ -134,7 +134,7 @@ public void Load() } LocalTimeRollover = logFile.LocalTimeRollover; - TruncateSize = logFile.TruncateSize; + TruncateSizeString = logFile.TruncateSize.ToString(); Period = (long)logFile.Period; } @@ -148,7 +148,7 @@ public void Load() public long Period { get; set; } - public long TruncateSize { get; set; } + public string TruncateSizeString { get; set; } public bool LocalTimeRollover { get; set; } @@ -272,7 +272,7 @@ public bool ApplyChanges() } element.Attributes["localTimeRollover"].Value = LocalTimeRollover; - element.Attributes["truncateSize"].Value = TruncateSize; + element.Attributes["truncateSize"].Value = TruncateSizeString; element.Attributes["period"].Value = Period; } else @@ -286,7 +286,21 @@ public bool ApplyChanges() } logFile.LocalTimeRollover = LocalTimeRollover; - logFile.TruncateSize = TruncateSize; + var dialog = (IManagementUIService)GetService(typeof(IManagementUIService)); + long size; + if (!long.TryParse(TruncateSizeString, out size)) + { + dialog.ShowMessage("The maximum file size must be a valid, positive integer.", Name, MessageBoxButtons.OK, MessageBoxIcon.Warning); + return false; + } + + if (size < 1048576 || size > 4294967295) + { + dialog.ShowMessage("The specified number is invalid. The valid range is between 1 MB and 4 GB.", Name, MessageBoxButtons.OK, MessageBoxIcon.Warning); + return false; + } + + logFile.TruncateSize = size; logFile.Period = (LoggingRolloverPeriod)Period; } diff --git a/JexusManager.Features.Logging/LoggingPage.Designer.cs b/JexusManager.Features.Logging/LoggingPage.Designer.cs index f2779f5a..6780ae25 100644 --- a/JexusManager.Features.Logging/LoggingPage.Designer.cs +++ b/JexusManager.Features.Logging/LoggingPage.Designer.cs @@ -36,7 +36,7 @@ private void InitializeComponent() this.cmsActionPanel = new System.Windows.Forms.ContextMenuStrip(this.components); this.label2 = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); - this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.gbRollover = new System.Windows.Forms.GroupBox(); this.cbLocalTime = new System.Windows.Forms.CheckBox(); this.rbNoFile = new System.Windows.Forms.RadioButton(); this.txtSize = new System.Windows.Forms.TextBox(); @@ -71,7 +71,7 @@ private void InitializeComponent() this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.panel2.SuspendLayout(); - this.groupBox3.SuspendLayout(); + this.gbRollover.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); @@ -124,7 +124,7 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel2.AutoScroll = true; - this.panel2.Controls.Add(this.groupBox3); + this.panel2.Controls.Add(this.gbRollover); this.panel2.Controls.Add(this.groupBox2); this.panel2.Controls.Add(this.label4); this.panel2.Controls.Add(this.cbLogType); @@ -134,21 +134,21 @@ private void InitializeComponent() this.panel2.Size = new System.Drawing.Size(560, 540); this.panel2.TabIndex = 7; // - // groupBox3 - // - this.groupBox3.Controls.Add(this.cbLocalTime); - this.groupBox3.Controls.Add(this.rbNoFile); - this.groupBox3.Controls.Add(this.txtSize); - this.groupBox3.Controls.Add(this.rbSize); - this.groupBox3.Controls.Add(this.cbSchedule); - this.groupBox3.Controls.Add(this.rbSchedule); - this.groupBox3.Controls.Add(this.label9); - this.groupBox3.Location = new System.Drawing.Point(6, 429); - this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(517, 219); - this.groupBox3.TabIndex = 7; - this.groupBox3.TabStop = false; - this.groupBox3.Text = "Log File Rollover"; + // gbRollover + // + this.gbRollover.Controls.Add(this.cbLocalTime); + this.gbRollover.Controls.Add(this.rbNoFile); + this.gbRollover.Controls.Add(this.txtSize); + this.gbRollover.Controls.Add(this.rbSize); + this.gbRollover.Controls.Add(this.cbSchedule); + this.gbRollover.Controls.Add(this.rbSchedule); + this.gbRollover.Controls.Add(this.label9); + this.gbRollover.Location = new System.Drawing.Point(6, 429); + this.gbRollover.Name = "gbRollover"; + this.gbRollover.Size = new System.Drawing.Size(517, 219); + this.gbRollover.TabIndex = 7; + this.gbRollover.TabStop = false; + this.gbRollover.Text = "Log File Rollover"; // // cbLocalTime // @@ -179,6 +179,7 @@ private void InitializeComponent() this.txtSize.Name = "txtSize"; this.txtSize.Size = new System.Drawing.Size(110, 20); this.txtSize.TabIndex = 4; + this.txtSize.TextChanged += new System.EventHandler(this.txtSize_TextChanged); // // rbSize // @@ -205,6 +206,7 @@ private void InitializeComponent() this.cbSchedule.Name = "cbSchedule"; this.cbSchedule.Size = new System.Drawing.Size(175, 21); this.cbSchedule.TabIndex = 2; + this.cbSchedule.SelectedIndexChanged += new System.EventHandler(this.cbSchedule_SelectedIndexChanged); // // rbSchedule // @@ -493,8 +495,8 @@ private void InitializeComponent() this.splitContainer1.ResumeLayout(false); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); - this.groupBox3.ResumeLayout(false); - this.groupBox3.PerformLayout(); + this.gbRollover.ResumeLayout(false); + this.gbRollover.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox1.ResumeLayout(false); @@ -531,7 +533,7 @@ private void InitializeComponent() private Panel panel2; private PictureBox pictureBox1; private ContextMenuStrip cmsActionPanel; - private GroupBox groupBox3; + private GroupBox gbRollover; private CheckBox cbLocalTime; private RadioButton rbNoFile; private TextBox txtSize; diff --git a/JexusManager.Features.Logging/LoggingPage.cs b/JexusManager.Features.Logging/LoggingPage.cs index 4e935b44..f77d30c9 100644 --- a/JexusManager.Features.Logging/LoggingPage.cs +++ b/JexusManager.Features.Logging/LoggingPage.cs @@ -5,11 +5,9 @@ namespace JexusManager.Features.Logging { using System; - using System.Collections; using System.Reflection; using System.Windows.Forms; - using JexusManager.Properties; using JexusManager.Services; using Microsoft.Web.Management.Client; @@ -33,6 +31,7 @@ public override void ShowHelp() } } + private const string MaxLogSize = "4294967295"; private PageTaskList _taskList; private LoggingFeature _feature; private bool _hasChanges; @@ -107,10 +106,11 @@ protected override void OnRefresh() cbFormat.SelectedIndex = (int)_feature.LogFormat; txtPath.Text = _feature.Directory; txtPath.Enabled = _feature.CanBrowse && _feature.IsEnabled; - btnSelect.Enabled = _feature.IsEnabled; + btnSelect.Enabled = _feature.CanBrowse && _feature.IsEnabled; btnBrowse.Enabled = _feature.CanBrowse && _feature.IsEnabled; cbFormat.Enabled = _feature.CanBrowse && _feature.IsEnabled; - cbEncoding.Enabled = _feature.CanEncoding; + cbEncoding.Enabled = _feature.CanEncoding && _feature.IsEnabled; + gbRollover.Enabled = _feature.CanBrowse && _feature.IsEnabled; rbFile.Enabled = rbEvent.Enabled = rbBoth.Enabled = _feature.LogTargetW3C == -1; if (_feature.LogTargetW3C != -1) @@ -129,31 +129,25 @@ protected override void OnRefresh() } } - if (_feature.Period == 0) - { - rbSize.Checked = true; - cbSchedule.Enabled = false; - txtSize.Text = _feature.TruncateSize.ToString(); - } - else + rbSchedule.Checked = cbSchedule.Enabled = _feature.Period > 0; + rbSize.Checked = txtSize.Enabled = _feature.Period == 0 && _feature.TruncateSizeString != MaxLogSize; + rbNoFile.Checked = _feature.Period == 0 && _feature.TruncateSizeString == MaxLogSize; + txtSize.Text = txtSize.Enabled ? _feature.TruncateSizeString.ToString() : string.Empty; + + switch (_feature.Period) { - rbSchedule.Checked = true; - txtSize.Enabled = false; - switch (_feature.Period) - { - case 2: - cbSchedule.SelectedIndex = 2; - break; - case 1: - cbSchedule.SelectedIndex = 1; - break; - case 4: - cbSchedule.SelectedIndex = 0; - break; - case 3: - cbSchedule.SelectedIndex = 3; - break; - } + case 2: + cbSchedule.SelectedIndex = 2; + break; + case 1: + cbSchedule.SelectedIndex = 1; + break; + case 4: + cbSchedule.SelectedIndex = 0; + break; + case 3: + cbSchedule.SelectedIndex = 3; + break; } cbLocalTime.Checked = _feature.LocalTimeRollover; @@ -192,7 +186,7 @@ protected override bool HasChanges protected override bool CanApplyChanges { - get { return true; } + get { return !rbSize.Checked || !string.IsNullOrWhiteSpace(txtSize.Text); } } private void cbEncoding_SelectedIndexChanged(object sender, EventArgs e) @@ -223,6 +217,7 @@ protected override void CancelChanges() private void btnSelect_Click(object sender, EventArgs e) { _feature.SelectFields(); + InformChanges(); } private void rbFile_CheckedChanged(object sender, EventArgs e) @@ -239,10 +234,14 @@ private void rbFile_CheckedChanged(object sender, EventArgs e) { _feature.LogTargetW3C = 3; } + + InformChanges(); } private void rbSchedule_CheckedChanged(object sender, EventArgs e) { + cbSchedule.Enabled = rbSchedule.Checked; + txtSize.Enabled = rbSize.Checked; if (rbSchedule.Checked) { switch (cbSchedule.SelectedIndex) @@ -264,13 +263,51 @@ private void rbSchedule_CheckedChanged(object sender, EventArgs e) else if (rbSize.Checked) { _feature.Period = 0; - _feature.TruncateSize = long.Parse(txtSize.Text); + _feature.TruncateSizeString = txtSize.Text; + } + else + { + _feature.Period = 0; + _feature.TruncateSizeString = MaxLogSize; } + + InformChanges(); } private void cbLocalTime_CheckedChanged(object sender, EventArgs e) { _feature.LocalTimeRollover = cbLocalTime.Checked; + InformChanges(); + } + + private void cbSchedule_SelectedIndexChanged(object sender, EventArgs e) + { + switch (cbSchedule.SelectedIndex) + { + case 0: + _feature.Period = 4; + break; + case 1: + _feature.Period = 1; + break; + case 2: + _feature.Period = 2; + break; + case 3: + _feature.Period = 3; + break; + } + + InformChanges(); + } + + private void txtSize_TextChanged(object sender, EventArgs e) + { + if (txtSize.Enabled) + { + _feature.TruncateSizeString = txtSize.Text; + InformChanges(); + } } } } diff --git a/JexusManager.Features.Logging/LoggingPage.resx b/JexusManager.Features.Logging/LoggingPage.resx index 950be5d2..5849981e 100644 --- a/JexusManager.Features.Logging/LoggingPage.resx +++ b/JexusManager.Features.Logging/LoggingPage.resx @@ -123,4 +123,7 @@ 17, 17 + + 17, 17 + \ No newline at end of file diff --git a/JexusManager.Shared/Services/ConfigurationService.cs b/JexusManager.Shared/Services/ConfigurationService.cs index 8260e577..6b13eaa7 100644 --- a/JexusManager.Shared/Services/ConfigurationService.cs +++ b/JexusManager.Shared/Services/ConfigurationService.cs @@ -68,6 +68,10 @@ public ConfigurationSection GetSection(string sectionPath, string locationPath = { section = config.GetSection(sectionPath, VirtualDirectory.LocationPath()); } + else if (Application != null) + { + section = config.GetSection(sectionPath, Application.LocationPath()); + } else { section = locationPath == null ? config.GetSection(sectionPath) : config.GetSection(sectionPath, locationPath); diff --git a/JexusManager/Properties/AssemblyInfo.cs b/JexusManager/Properties/AssemblyInfo.cs index d8ea62c9..2c8eebeb 100644 --- a/JexusManager/Properties/AssemblyInfo.cs +++ b/JexusManager/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ + "190a69a439dbfb969ebad72a6f7e2e047907da4a7b9c08c6e98d5f1be8b8cafaf3eb978914059a" + "245d4bc1")] -[assembly: AssemblyVersion("2.1.0.55")] -[assembly: AssemblyFileVersion("2.1.0.55")] +[assembly: AssemblyVersion("2.1.0.56")] +[assembly: AssemblyFileVersion("2.1.0.56")] diff --git a/Microsoft.Web.Administration/CommonHelper.cs b/Microsoft.Web.Administration/CommonHelper.cs index b29690f4..29b5a9c1 100644 --- a/Microsoft.Web.Administration/CommonHelper.cs +++ b/Microsoft.Web.Administration/CommonHelper.cs @@ -111,6 +111,11 @@ internal static string LocationPath(this VirtualDirectory virtualDirectory) return virtualDirectory.Application.Site.Name + virtualDirectory.PathToSite(); } + internal static string LocationPath(this Application application) + { + return application.Site.Name + application.Path; + } + internal static bool IsJexus(ServerManager server, Application application) { if (server != null)