-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CrashDumper: Allow app configuration of dump directory
For detailed information, see 'docs/dev-crashdumpconfig'. Add a config section to specify the dump path, and clean up parameters before creating a new dump. <configSections> <sectionGroup name="CrashReporter"> <section name="CrashDumper" type="RJCP.Diagnostics.Config.CrashDumper, RJCP.Diagnostics.CrashReporter"/> </sectionGroup> </configSections> <CrashReporter> <CrashDumper> <DumpDirectory path="${LOCALAPPDIR}/CrashDumps" ageDays="45" maxLogs="40" freeGb="5" freePercent="1" maxGb="1" minLogs="5"/> </CrashDumper> </CrashReporter> Issue: HELIOS-1347
- Loading branch information
Showing
28 changed files
with
737 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace RJCP.Diagnostics.Config | ||
{ | ||
using System.Configuration; | ||
|
||
internal class CrashDumper : ConfigurationSection | ||
{ | ||
[ConfigurationProperty("DumpDirectory", IsRequired = false)] | ||
public DumpDirElement DumpDir | ||
{ | ||
get { return (DumpDirElement)this["DumpDirectory"]; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace RJCP.Diagnostics.Config.CrashReporter | ||
{ | ||
/// <summary> | ||
/// CrashDumper Configuration. | ||
/// </summary> | ||
public class CrashDumperConfig | ||
{ | ||
internal CrashDumperConfig() | ||
{ | ||
DumpDir = new DumpDir(); | ||
} | ||
|
||
internal CrashDumperConfig(CrashDumper config) | ||
{ | ||
DumpDir = new DumpDir(config.DumpDir); | ||
} | ||
|
||
/// <summary> | ||
/// Gets configuration properties for the dump directory. | ||
/// </summary> | ||
/// <value>The dump directory configuration properties.</value> | ||
public DumpDir DumpDir { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
namespace RJCP.Diagnostics.Config.CrashReporter | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Configuration on managing the dump directory. | ||
/// </summary> | ||
public class DumpDir | ||
{ | ||
internal DumpDir() | ||
{ | ||
Path = System.IO.Path.Combine( | ||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), | ||
"CrashDumps"); | ||
AgeDays = 45; | ||
MaxLogs = 40; | ||
ReserveFree = 5; | ||
ReserveFreePercent = 1; | ||
MaxDirSize = 1; | ||
MaxDirSizeMinLogs = 5; | ||
} | ||
|
||
internal DumpDir(DumpDirElement dumpDir) : this() | ||
{ | ||
string path = Parser.ParseEnvVar(dumpDir.Path); | ||
if (path != null) Path = path; | ||
|
||
if (int.TryParse(dumpDir.AgeDays, out int ageDays)) { | ||
if (ageDays <= 0) ageDays = 1; | ||
AgeDays = ageDays; | ||
} | ||
|
||
if (int.TryParse(dumpDir.MaxLogs, out int maxLogs)) { | ||
if (maxLogs <= 0) maxLogs = 1; | ||
MaxLogs = maxLogs; | ||
} | ||
|
||
if (int.TryParse(dumpDir.ReserveFree, out int reserveFree)) { | ||
if (reserveFree <= 0) reserveFree = 1; | ||
ReserveFree = reserveFree; | ||
} | ||
|
||
if (int.TryParse(dumpDir.ReserveFreePercent, out int reserveFreePercent)) { | ||
if (reserveFreePercent < 0) reserveFreePercent = 0; | ||
if (reserveFreePercent > 99) reserveFreePercent = 99; | ||
ReserveFreePercent = reserveFreePercent; | ||
} | ||
|
||
if (int.TryParse(dumpDir.MaxDirSize, out int maxDirSize)) { | ||
if (maxDirSize <= 0) maxDirSize = 1; | ||
MaxDirSize = maxDirSize; | ||
} | ||
|
||
if (int.TryParse(dumpDir.MaxDirSizeMinLogs, out int maxDirSizeMinLogs)) { | ||
if (maxDirSizeMinLogs <= 0) maxDirSizeMinLogs = 1; | ||
MaxDirSizeMinLogs = maxDirSizeMinLogs; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the directory path where to store the dump files. | ||
/// </summary> | ||
/// <value>The directory path where to store the dump files.</value> | ||
public string Path { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the age, in days, from when to start removing old dump files. | ||
/// </summary> | ||
/// <value>The age days when to start removing old dump files.</value> | ||
public int AgeDays { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the maximum logs to keep in the dump directory. | ||
/// </summary> | ||
/// <value>The maximum logs of logs to keep in the dump directory.</value> | ||
public int MaxLogs { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the reserved free space in gigabytes. | ||
/// </summary> | ||
/// <value>The reserved free space in gigabytes.</value> | ||
public int ReserveFree { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the reserved free space as a percentage. | ||
/// </summary> | ||
/// <value>The reserved free space as a percentage.</value> | ||
public int ReserveFreePercent { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the maximum size of the dump directory. | ||
/// </summary> | ||
/// <value>The maximum size of the dump directory.</value> | ||
public int MaxDirSize { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the minimum number of logs to keep if the max size of the directory is exceeded. | ||
/// </summary> | ||
/// <value>The minimum number of logs to keep if the max size of the directory is exceeded.</value> | ||
public int MaxDirSizeMinLogs { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace RJCP.Diagnostics.Config.CrashReporter.EnvVar | ||
{ | ||
internal interface IToken { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace RJCP.Diagnostics.Config.CrashReporter.EnvVar | ||
{ | ||
internal class TokenString : IToken | ||
{ | ||
public TokenString(string value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public string Value { get; private set; } | ||
|
||
public override string ToString() | ||
{ | ||
return Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace RJCP.Diagnostics.Config.CrashReporter.EnvVar | ||
{ | ||
using System; | ||
using System.IO; | ||
|
||
internal class TokenVar : IToken | ||
{ | ||
public TokenVar(string envVar) | ||
{ | ||
if (envVar.Equals("LOCALAPPDATA", StringComparison.Ordinal)) { | ||
Value = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
} else if (envVar.Equals("APPDATA", StringComparison.Ordinal)) { | ||
Value = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); | ||
} else if (envVar.Equals("HOME", StringComparison.Ordinal)) { | ||
if (Platform.IsWinNT()) { | ||
string userProfile = Environment.GetEnvironmentVariable("USERPROFILE"); | ||
if (!string.IsNullOrWhiteSpace(userProfile)) { | ||
Value = userProfile; | ||
} else { | ||
Value = string.Format("{0}{1}", | ||
Environment.GetEnvironmentVariable("HOMEDRIVE"), | ||
Environment.GetEnvironmentVariable("HOMEPATH")); | ||
} | ||
} else { | ||
Value = Environment.GetEnvironmentVariable("HOME"); | ||
} | ||
} else if (envVar.Equals("CWD", StringComparison.Ordinal)) { | ||
Value = Environment.CurrentDirectory; | ||
} else if (envVar.Equals("APPDIR", StringComparison.Ordinal)) { | ||
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; | ||
Value = Path.GetDirectoryName(assemblyPath); | ||
} else { | ||
Value = Environment.GetEnvironmentVariable(envVar); | ||
} | ||
} | ||
|
||
public string Value { get; private set; } | ||
|
||
public override string ToString() | ||
{ | ||
return Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace RJCP.Diagnostics.Config.CrashReporter.EnvVar | ||
{ | ||
internal enum VarState | ||
{ | ||
Expansion, | ||
Token, | ||
VariableStart, | ||
Variable | ||
} | ||
} |
Oops, something went wrong.