diff --git a/README.md b/README.md index e6c3a7ec..334c1e1b 100644 --- a/README.md +++ b/README.md @@ -850,7 +850,8 @@ This health reporter writes all errors, warnings, and informational traces gener "minReportLevel": "Warning", "throttlingPeriodMsec": "1000", "singleLogFileMaximumSizeInMBytes": "8192", - "logRetentionInDays": "30" + "logRetentionInDays": "30", + "ensureOutputCanBeSaved": "false" } ``` | Field | Values/Types | Required | Description | @@ -862,9 +863,9 @@ This health reporter writes all errors, warnings, and informational traces gener | `throttlingPeriodMsec` | number of milliseconds | No | Specifies the throttling time period. This setting protects the health reporter from being overwhelmed, which can happen if a message is repeatedly generated due to an error in the pipeline. Default is 0, for no throttling. | | `singleLogFileMaximumSizeInMBytes` | File size in MB/number | No | Specifies the size of the log file in MB before rotating happens. The default value is 8192 MB (8 GB). Once the size of log file exceeds the value, it will be renamed from fileName.csv to fileName_last.csv. Then logs will be written to a new fileName.csv. This setting prevents a single log file become too big. | | `logRetentionInDays` | number of days for the logs files retain | No | Specifies how long log files will be retained. The default value is 30 days. Any log files created earlier than the specified number of days ago will be removed automatically. This prevents continuous generation of logs that might lead to storage exhaustion. | +| `ensureOutputCanBeSaved` | boolean | No | Specifies whether the health reporter is going to ensure the permission to write to the log folder. The default value is `false`. When set to `true`, it will prevent the pipeline creation when it can't write the log. Otherwise, it will ignore the error. - -CsvHealthReporter will try to open the log file for writing during initialization. If it can't, a debug message will be output to the debugger viewer like Visual Studio Output window, etc. This can happen especially if a value for the log file path is not provided (default is used, which is application executables folder) and the application executables are residing on a read-only file system. Docker tools for Visual Studio use this configuration during debugging, so for containerized services the recommended practice is to specify the log file path explicitly. +CsvHealthReporter will try to open the log file for writing during initialization. If it can't, by default, a debug message will be output to the debugger viewer like Visual Studio Output window, etc. This can happen especially if a value for the log file path is not provided (default is used, which is application executables folder) and the application executables are residing on a read-only file system. Docker tools for Visual Studio use this configuration during debugging, so for containerized services the recommended practice is to specify the log file path explicitly. ### Pipeline Settings The EventFlow configuration has settings allowing the application to adjust certain behaviors of the pipeline. These range from how many events the pipeline buffer, to the timeout the pipeline should use when waiting for an operation. If this section is omitted, the pipeline will use default settings. diff --git a/src/Microsoft.Diagnostics.EventFlow.Consumers.ConsoleAppCore/config.json b/src/Microsoft.Diagnostics.EventFlow.Consumers.ConsoleAppCore/config.json index 4df3862d..8786eb06 100644 --- a/src/Microsoft.Diagnostics.EventFlow.Consumers.ConsoleAppCore/config.json +++ b/src/Microsoft.Diagnostics.EventFlow.Consumers.ConsoleAppCore/config.json @@ -19,7 +19,7 @@ "throttlingPeriodMsec": "1000", "singleLogFileMaximumSizeInMBytes": 1, "logRetentionInDays": 1, - "isDebugMode": false + "ensureOutputCanBeSaved": false }, "schema-version": "2016-08-11" } diff --git a/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporter.cs b/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporter.cs index 49cf4158..393f89a9 100644 --- a/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporter.cs +++ b/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporter.cs @@ -61,7 +61,7 @@ private static class FileSuffix private int flushPeriodMsec = 5000; private FileStream fileStream; internal StreamWriter StreamWriter; - internal bool IsDebugMode { get; private set; } + internal bool EnsureOutputCanBeSaved { get; private set; } internal long SingleLogFileMaximumSizeInBytes { get; private set; } #endregion @@ -132,7 +132,7 @@ public void Activate() if (StreamWriter == null) { message = $"Fail to set new stream writer for {nameof(CsvHealthReporter)}."; - if (IsDebugMode) + if (EnsureOutputCanBeSaved) { throw new InvalidOperationException(message); } @@ -146,7 +146,7 @@ public void Activate() } catch (UnauthorizedAccessException ex) { - if (IsDebugMode) + if (EnsureOutputCanBeSaved) { throw; } @@ -395,7 +395,7 @@ private void Initialize(CsvHealthReporterConfiguration configuration, INewReport this.reportCollection = new BlockingCollection(); - this.IsDebugMode = configuration.IsDebugMode; + this.EnsureOutputCanBeSaved = configuration.EnsureOutputCanBeSaved; this.innerReportWriter = this.ReportText; diff --git a/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporterConfiguration.cs b/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporterConfiguration.cs index e1ac6a25..16c506cb 100644 --- a/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporterConfiguration.cs +++ b/src/Microsoft.Diagnostics.EventFlow.Core/Implementations/HealthReporters/CsvHealthReporterConfiguration.cs @@ -15,6 +15,6 @@ public class CsvHealthReporterConfiguration public int? ThrottlingPeriodMsec { get; set; } public int SingleLogFileMaximumSizeInMBytes { get; set; } public int LogRetentionInDays { get; set; } - public bool IsDebugMode { get; set; } + public bool EnsureOutputCanBeSaved { get; set; } } } diff --git a/src/Microsoft.Diagnostics.EventFlow.Core/Microsoft.Diagnostics.EventFlow.Core.csproj b/src/Microsoft.Diagnostics.EventFlow.Core/Microsoft.Diagnostics.EventFlow.Core.csproj index d9410baa..3e61e8c9 100644 --- a/src/Microsoft.Diagnostics.EventFlow.Core/Microsoft.Diagnostics.EventFlow.Core.csproj +++ b/src/Microsoft.Diagnostics.EventFlow.Core/Microsoft.Diagnostics.EventFlow.Core.csproj @@ -21,7 +21,7 @@ false false false - 1.1.7 + 1.1.8 diff --git a/test/Microsoft.Diagnostics.EventFlow.Core.Tests/CsvHealthReporterTests.cs b/test/Microsoft.Diagnostics.EventFlow.Core.Tests/CsvHealthReporterTests.cs index 3aa35012..7ec6c75b 100644 --- a/test/Microsoft.Diagnostics.EventFlow.Core.Tests/CsvHealthReporterTests.cs +++ b/test/Microsoft.Diagnostics.EventFlow.Core.Tests/CsvHealthReporterTests.cs @@ -28,7 +28,7 @@ public class CsvHealthReporterTests private const string ThrottlingPeriodMsecKey = "ThrottlingPeriodMsec"; private const string SingleLogFileMaximumSizeInMBytesKey = "SingleLogFileMaximumSizeInMBytes"; private const string LogRetentionInDaysKey = "LogRetentionInDays"; - private const string IsDebugModeKey = "IsDebugMode"; + private const string EnsureOutputCanBeSavedKey = "EnsureOutputCanBeSaved"; private const int DefaultDelayMsec = 100; [Fact] @@ -370,10 +370,10 @@ public void ShouldHandleUnauthorizedAccessWhenCreatingTheFileStream() } [Fact] - public void ShouldThrowUnauthorizedAccessWhenIsDebugModeIsOn() + public void ShouldThrowUnauthorizedAccessWhenEnsureOutputCanBeSavedIsOn() { var configuration = BuildTestConfigration(); - configuration[IsDebugModeKey] = "true"; + configuration[EnsureOutputCanBeSavedKey] = "true"; string exceptionMessage = "Simulate no permission to write the file."; using (CustomHealthReporter target = new CustomHealthReporter(configuration, 1000, setNewStreamWriter: () => throw new UnauthorizedAccessException(exceptionMessage))) { @@ -429,30 +429,30 @@ public void ShouldCleanUpExistingLogsPerRetentionPolicy() } [Fact] - public void ShouldSetIsDebugModeToFalseByDefault() + public void ShouldSetEnsureOutputCanBeSavedToFalseByDefault() { var configuration = BuildTestConfigration(); - Assert.Null(configuration[IsDebugModeKey]); + Assert.Null(configuration[EnsureOutputCanBeSavedKey]); using (CustomHealthReporter target = new CustomHealthReporter(configuration)) { - Assert.False(target.IsDebugMode); + Assert.False(target.EnsureOutputCanBeSaved); } } [Fact] - public void ShouldSetIsDebugModeByConfiguration() + public void ShouldSetEnsureOutputCanBeSavedByConfiguration() { var configuration = BuildTestConfigration(); - configuration[IsDebugModeKey] = "true"; + configuration[EnsureOutputCanBeSavedKey] = "true"; using (CustomHealthReporter target = new CustomHealthReporter(configuration)) { - Assert.True(target.IsDebugMode); + Assert.True(target.EnsureOutputCanBeSaved); } - configuration[IsDebugModeKey] = "false"; + configuration[EnsureOutputCanBeSavedKey] = "false"; using (CustomHealthReporter target = new CustomHealthReporter(configuration)) { - Assert.False(target.IsDebugMode); + Assert.False(target.EnsureOutputCanBeSaved); } }