Skip to content

Commit

Permalink
Fixed logging truncate size support.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Dec 29, 2017
1 parent eb2daa2 commit 0b960bd
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 59 deletions.
26 changes: 20 additions & 6 deletions JexusManager.Features.Logging/LoggingFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -134,7 +134,7 @@ public void Load()
}

LocalTimeRollover = logFile.LocalTimeRollover;
TruncateSize = logFile.TruncateSize;
TruncateSizeString = logFile.TruncateSize.ToString();
Period = (long)logFile.Period;
}

Expand All @@ -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; }

Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
44 changes: 23 additions & 21 deletions JexusManager.Features.Logging/LoggingPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 67 additions & 30 deletions JexusManager.Features.Logging/LoggingPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +31,7 @@ public override void ShowHelp()
}
}

private const string MaxLogSize = "4294967295";
private PageTaskList _taskList;
private LoggingFeature _feature;
private bool _hasChanges;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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();
}
}
}
}
3 changes: 3 additions & 0 deletions JexusManager.Features.Logging/LoggingPage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@
<metadata name="tsActionPanel.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="tsActionPanel.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
4 changes: 4 additions & 0 deletions JexusManager.Shared/Services/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions JexusManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
5 changes: 5 additions & 0 deletions Microsoft.Web.Administration/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0b960bd

Please sign in to comment.