Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 1c9dcb0

Browse files
authored
Fix comments, typos and add property validation to Microsoft.Extensions.Logging.AzureAppServices (#509)
1 parent 2b2e0c6 commit 1c9dcb0

File tree

4 files changed

+124
-16
lines changed

4 files changed

+124
-16
lines changed

src/Microsoft.Extensions.Logging.AzureAppServices/AzureAppServicesDiagnosticsSettings.cs

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,152 @@ namespace Microsoft.Extensions.Logging.AzureAppServices
1111
/// </summary>
1212
public class AzureAppServicesDiagnosticsSettings
1313
{
14+
private TimeSpan _blobCommitPeriod = TimeSpan.FromSeconds(5);
15+
private int _blobBatchSize = 32;
16+
private string _outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
17+
private int _retainedFileCountLimit = 2;
18+
private int _fileSizeLimit = 10 * 1024 * 1024;
19+
private string _blobName = "applicationLog.txt";
20+
private TimeSpan? _fileFlushPeriod = TimeSpan.FromSeconds(1);
21+
private int _backgroundQueueSize;
22+
1423
/// <summary>
15-
/// Gets or sets a strictly positive value representing the maximum log size in bytes. Once the log is full, no more message will be appended.
24+
/// Gets or sets a strictly positive value representing the maximum log size in bytes.
25+
/// Once the log is full, no more messages will be appended.
26+
/// Defaults to <c>10MB</c>.
1627
/// </summary>
17-
public int FileSizeLimit { get; set; } = 10 * 1024 * 1024;
28+
public int FileSizeLimit
29+
{
30+
get { return _fileSizeLimit; }
31+
set
32+
{
33+
if (value <= 0)
34+
{
35+
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(FileSizeLimit)} must be positive.");
36+
}
37+
_fileSizeLimit = value;
38+
}
39+
}
1840

1941
/// <summary>
2042
/// Gets or sets a strictly positive value representing the maximum retained file count.
43+
/// Defaults to <c>2</c>.
2144
/// </summary>
22-
public int RetainedFileCountLimit { get; set; } = 2;
45+
public int RetainedFileCountLimit
46+
{
47+
get { return _retainedFileCountLimit; }
48+
set
49+
{
50+
if (value <= 0)
51+
{
52+
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(RetainedFileCountLimit)} must be positive.");
53+
}
54+
_retainedFileCountLimit = value;
55+
}
56+
}
2357

2458
/// <summary>
2559
/// Gets or sets a message template describing the output messages.
60+
/// Defaults to <c>"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"</c>.
2661
/// </summary>
27-
public string OutputTemplate { get; set; } = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
62+
public string OutputTemplate
63+
{
64+
get { return _outputTemplate; }
65+
set
66+
{
67+
if (string.IsNullOrWhiteSpace(value))
68+
{
69+
throw new ArgumentException(nameof(value), $"{nameof(OutputTemplate)} must be non-empty string.");
70+
}
71+
_outputTemplate = value;
72+
}
73+
}
2874

2975
/// <summary>
3076
/// Gets or sets a maximum number of events to include in a single blob append batch.
77+
/// Defaults to <c>32</c>.
3178
/// </summary>
32-
public int BlobBatchSize { get; set; } = 32;
79+
public int BlobBatchSize
80+
{
81+
get { return _blobBatchSize; }
82+
set
83+
{
84+
if (value <= 0)
85+
{
86+
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(BlobBatchSize)} must be positive.");
87+
}
88+
_blobBatchSize = value;
89+
}
90+
}
3391

3492
/// <summary>
3593
/// Gets or sets a time to wait between checking for blob log batches.
94+
/// Defaults to 5 seconds.
3695
/// </summary>
37-
public TimeSpan BlobCommitPeriod { get; set; } = TimeSpan.FromSeconds(5);
96+
public TimeSpan BlobCommitPeriod
97+
{
98+
get { return _blobCommitPeriod; }
99+
set
100+
{
101+
if (value < TimeSpan.Zero)
102+
{
103+
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(BlobCommitPeriod)} must be positive.");
104+
}
105+
_blobCommitPeriod = value;
106+
}
107+
}
38108

39109
/// <summary>
40110
/// Gets or sets the last section of log blob name.
111+
/// Defaults to <c>"applicationLog.txt"</c>.
41112
/// </summary>
42-
public string BlobName { get; set; } = "applicationLog.txt";
113+
public string BlobName
114+
{
115+
get { return _blobName; }
116+
set
117+
{
118+
if (string.IsNullOrWhiteSpace(value))
119+
{
120+
throw new ArgumentException(nameof(value), $"{nameof(BlobName)} must be non-empty string.");
121+
}
122+
_blobName = value;
123+
}
124+
}
43125

44126
/// <summary>
45-
/// Gets of sets the maximum size of the background log message queue.
127+
/// Gets or sets the maximum size of the background log message queue or 0 for no limit.
128+
/// After maximum queue size is reached log event sink would start blocking.
129+
/// Defaults to <c>0</c>.
46130
/// </summary>
47-
public int BackgroundQueueSize { get; set; }
131+
public int BackgroundQueueSize
132+
{
133+
get { return _backgroundQueueSize; }
134+
set
135+
{
136+
if (value < 0)
137+
{
138+
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(BackgroundQueueSize)} must be positive or 0.");
139+
}
140+
_backgroundQueueSize = value;
141+
}
142+
}
48143

49144
/// <summary>
50-
/// Gets or sets the period after which logs will be flushed to disk.
145+
/// Gets or sets the period after which logs will be flushed to disk or
146+
/// <c>null</c> if auto flushing is not required.
147+
/// Defaults to 1 second.
51148
/// </summary>
52-
public TimeSpan? FileFlushPeriod { get; set; } = TimeSpan.FromSeconds(1);
149+
public TimeSpan? FileFlushPeriod
150+
{
151+
get { return _fileFlushPeriod; }
152+
set
153+
{
154+
if (value < TimeSpan.Zero)
155+
{
156+
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(FileFlushPeriod)} must be positive.");
157+
}
158+
_fileFlushPeriod = value;
159+
}
160+
}
53161
}
54162
}

src/Microsoft.Extensions.Logging.AzureAppServices/Internal/AzureBlobSink.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public AzureBlobSink(Func<string, ICloudAppendBlob> blobReferenceFactory,
5454
}
5555
if (batchSizeLimit <= 0)
5656
{
57-
throw new ArgumentOutOfRangeException(nameof(batchSizeLimit), $"{nameof(batchSizeLimit)} should be a positive number.");
57+
throw new ArgumentOutOfRangeException(nameof(batchSizeLimit), $"{nameof(batchSizeLimit)} must be a positive number.");
5858
}
5959
if (period <= TimeSpan.Zero)
6060
{
61-
throw new ArgumentOutOfRangeException(nameof(period), $"{nameof(period)} should be longer than zero.");
61+
throw new ArgumentOutOfRangeException(nameof(period), $"{nameof(period)} must be longer than zero.");
6262
}
6363

6464
_appName = appName;

src/Microsoft.Extensions.Logging.AzureAppServices/Internal/FileLoggerProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public FileLoggerProvider(int fileSizeLimit, int retainedFileCountLimit, int bac
4040
}
4141
if (fileSizeLimit <= 0)
4242
{
43-
throw new ArgumentOutOfRangeException(nameof(fileSizeLimit), $"{nameof(fileSizeLimit)} should be positive.");
43+
throw new ArgumentOutOfRangeException(nameof(fileSizeLimit), $"{nameof(fileSizeLimit)} must be positive.");
4444
}
4545
if (retainedFileCountLimit <= 0)
4646
{
47-
throw new ArgumentOutOfRangeException(nameof(retainedFileCountLimit), $"{nameof(retainedFileCountLimit)} should be positive.");
47+
throw new ArgumentOutOfRangeException(nameof(retainedFileCountLimit), $"{nameof(retainedFileCountLimit)} must be positive.");
4848
}
4949

5050
_fileSizeLimit = fileSizeLimit;

src/Microsoft.Extensions.Logging.AzureAppServices/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": "1.0.0-*",
3-
"description": "Diagnostics logger for Azure WebApps",
3+
"description": "Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.",
44
"packOptions": {
55
"tags": [
66
"logging"

0 commit comments

Comments
 (0)