7
7
using System . Threading . Tasks ;
8
8
using Microsoft . Azure . Cosmos . Table ;
9
9
using Microsoft . Azure . WebJobs . Host . Executors ;
10
+ using Microsoft . Azure . WebJobs . Logging ;
10
11
using Microsoft . Azure . WebJobs . Script . WebHost . Helpers ;
11
12
using Microsoft . Extensions . Configuration ;
12
13
using Microsoft . Extensions . Logging ;
@@ -16,21 +17,20 @@ namespace Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics
16
17
public class DiagnosticEventTableStorageRepository : IDiagnosticEventRepository , IDisposable
17
18
{
18
19
internal const string TableNamePrefix = "AzureFunctionsDiagnosticEvents" ;
19
- private const int LogFlushInterval = 1000 * 60 * 10 ; // 10 mins
20
+ private const int LogFlushInterval = 1000 * 60 * 10 ; // 10 minutes
21
+ private const int TableCreationMaxRetryCount = 5 ;
22
+
20
23
private readonly Timer _flushLogsTimer ;
24
+ private readonly IConfiguration _configuration ;
25
+ private readonly IHostIdProvider _hostIdProvider ;
26
+ private readonly IEnvironment _environment ;
27
+ private readonly ILogger < DiagnosticEventTableStorageRepository > _logger ;
28
+ private readonly object _syncLock = new object ( ) ;
21
29
22
- private int _tableCreationRetries = 5 ;
23
30
private ConcurrentDictionary < string , DiagnosticEvent > _events = new ConcurrentDictionary < string , DiagnosticEvent > ( ) ;
24
-
25
- private IConfiguration _configuration ;
26
- private IHostIdProvider _hostIdProvider ;
27
- private IEnvironment _environment ;
28
- private ILogger < DiagnosticEventTableStorageRepository > _logger ;
29
-
30
31
private CloudTableClient _tableClient ;
31
32
private CloudTable _diagnosticEventsTable ;
32
33
private string _hostId ;
33
- private object _syncLock = new object ( ) ;
34
34
private bool _disposed = false ;
35
35
private string _tableName ;
36
36
@@ -81,13 +81,7 @@ internal string HostId
81
81
}
82
82
}
83
83
84
- internal ConcurrentDictionary < string , DiagnosticEvent > Events
85
- {
86
- get
87
- {
88
- return _events ;
89
- }
90
- }
84
+ internal ConcurrentDictionary < string , DiagnosticEvent > Events => _events ;
91
85
92
86
internal CloudTable GetDiagnosticEventsTable ( DateTime ? now = null )
93
87
{
@@ -135,7 +129,7 @@ internal virtual async Task FlushLogs(CloudTable table = null)
135
129
return ;
136
130
}
137
131
138
- bool tableCreated = await TableStorageHelpers . CreateIfNotExistsAsync ( table , _tableCreationRetries ) ;
132
+ bool tableCreated = await TableStorageHelpers . CreateIfNotExistsAsync ( table , TableCreationMaxRetryCount ) ;
139
133
if ( tableCreated )
140
134
{
141
135
TableStorageHelpers . QueueBackgroundTablePurge ( table , TableClient , TableNamePrefix , _logger ) ;
@@ -153,7 +147,7 @@ internal virtual async Task FlushLogs(CloudTable table = null)
153
147
// All existing events are logged to other logging pipelines already.
154
148
ConcurrentDictionary < string , DiagnosticEvent > tempDictionary = _events ;
155
149
_events = new ConcurrentDictionary < string , DiagnosticEvent > ( ) ;
156
- if ( tempDictionary . Count > 0 )
150
+ if ( ! tempDictionary . IsEmpty )
157
151
{
158
152
await ExecuteBatchAsync ( tempDictionary , table ) ;
159
153
}
@@ -166,7 +160,10 @@ internal async Task ExecuteBatchAsync(ConcurrentDictionary<string, DiagnosticEve
166
160
var batch = new TableBatchOperation ( ) ;
167
161
foreach ( string errorCode in events . Keys )
168
162
{
169
- TableOperation insertOperation = TableOperation . Insert ( events [ errorCode ] ) ;
163
+ var diagnosticEvent = events [ errorCode ] ;
164
+ diagnosticEvent . Message = Sanitizer . Sanitize ( diagnosticEvent . Message ) ;
165
+ diagnosticEvent . Details = Sanitizer . Sanitize ( diagnosticEvent . Details ) ;
166
+ TableOperation insertOperation = TableOperation . Insert ( diagnosticEvent ) ;
170
167
batch . Add ( insertOperation ) ;
171
168
}
172
169
await table . ExecuteBatchAsync ( batch ) ;
@@ -205,7 +202,7 @@ public void WriteDiagnosticEvent(DateTime timestamp, string errorCode, LogLevel
205
202
}
206
203
}
207
204
208
- internal void StopTimer ( )
205
+ private void StopTimer ( )
209
206
{
210
207
_logger . LogInformation ( "Stopping the flush logs timer" ) ;
211
208
_flushLogsTimer ? . Change ( Timeout . Infinite , Timeout . Infinite ) ;
0 commit comments