@@ -110,7 +110,7 @@ index 2c20d1b1..63957a5d 100644
110
110
public static readonly Architecture PlatformArchitecture = Architecture.X64;
111
111
#endif
112
112
diff --git a/src/Runner.Common/HostTraceListener.cs b/src/Runner.Common/HostTraceListener.cs
113
- index c1953d88..61561ba7 100644
113
+ index c1953d88..f48d9581 100644
114
114
--- a/src/Runner.Common/HostTraceListener.cs
115
115
+++ b/src/Runner.Common/HostTraceListener.cs
116
116
@@ -4,19 +4,21 @@ using System.Diagnostics;
@@ -150,7 +150,7 @@ index c1953d88..61561ba7 100644
150
150
_currentPageSize = 0;
151
151
}
152
152
153
- @@ -49,12 +51,10 @@ namespace GitHub.Runner.Common
153
+ @@ -49,7 +51,7 @@ namespace GitHub.Runner.Common
154
154
{
155
155
ArgUtil.NotNullOrEmpty(logFile, nameof(logFile));
156
156
Directory.CreateDirectory(Path.GetDirectoryName(logFile));
@@ -159,12 +159,7 @@ index c1953d88..61561ba7 100644
159
159
Writer = new StreamWriter(logStream);
160
160
}
161
161
162
- - // Copied and modified slightly from .Net Core source code. Modification was required to make it compile.
163
- - // There must be some TraceFilter extension class that is missing in this source code.
164
- public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
165
- {
166
- if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))
167
- @@ -69,10 +69,16 @@ namespace GitHub.Runner.Common
162
+ @@ -69,10 +71,16 @@ namespace GitHub.Runner.Common
168
163
169
164
public override void WriteLine(string message)
170
165
{
@@ -183,7 +178,7 @@ index c1953d88..61561ba7 100644
183
178
_currentPageSize += messageSize;
184
179
if (_currentPageSize > _pageSizeLimit)
185
180
{
186
- @@ -93,10 +99 ,16 @@ namespace GitHub.Runner.Common
181
+ @@ -93,10 +101 ,16 @@ namespace GitHub.Runner.Common
187
182
188
183
public override void Write(string message)
189
184
{
@@ -202,7 +197,7 @@ index c1953d88..61561ba7 100644
202
197
_currentPageSize += messageSize;
203
198
}
204
199
205
- @@ -111,30 +123 ,17 @@ namespace GitHub.Runner.Common
200
+ @@ -111,30 +125 ,17 @@ namespace GitHub.Runner.Common
206
201
// Altered from the original .Net Core implementation.
207
202
private void WriteHeader(string source, TraceEventType eventType, int id)
208
203
{
@@ -243,7 +238,7 @@ index c1953d88..61561ba7 100644
243
238
}
244
239
245
240
// Copied and modified slightly from .Net Core source code to make it compile. The original code
246
- @@ -164,38 +163 ,43 @@ namespace GitHub.Runner.Common
241
+ @@ -164,38 +165 ,43 @@ namespace GitHub.Runner.Common
247
242
{
248
243
if (_enableLogRetention)
249
244
{
@@ -309,7 +304,7 @@ index c1953d88..61561ba7 100644
309
304
}
310
305
}
311
306
diff --git a/src/Runner.Common/Logging.cs b/src/Runner.Common/Logging.cs
312
- index 9200ca59..6fa0decc 100644
307
+ index 9200ca59..eefa042b 100644
313
308
--- a/src/Runner.Common/Logging.cs
314
309
+++ b/src/Runner.Common/Logging.cs
315
310
@@ -1,5 +1,7 @@
@@ -320,93 +315,8 @@ index 9200ca59..6fa0decc 100644
320
315
321
316
namespace GitHub.Runner.Common
322
317
{
323
- @@ -8,10 +10,8 @@ namespace GitHub.Runner.Common
324
- {
325
- long TotalLines { get; }
326
- void Setup(Guid timelineId, Guid timelineRecordId);
327
- -
328
- - void Write(string message);
329
- -
330
- - void End();
331
- + Task WriteAsync(string message); // Changed to async
332
- + Task EndAsync();
333
- }
334
-
335
- public class PagingLogger : RunnerService, IPagingLogger
336
- @@ -70,98 +70,93 @@ namespace GitHub.Runner.Common
337
- // and the consumer queues it for upload
338
- // Ensure this is lazy. Create a page on first write
339
- //
340
- - public void Write(string message)
341
- + public async Task WriteAsync(string message)
342
- {
343
- // lazy creation on write
344
- if (_pageWriter == null)
345
- {
346
- - NewPage();
347
- + await NewPageAsync();
348
- }
349
-
350
- if (_resultsBlockWriter == null)
351
- {
352
- - NewBlock();
353
- + await NewBlockAsync();
354
- }
355
-
356
- - string line = $"{DateTime.UtcNow.ToString("O")} {message}";
357
- - _pageWriter.WriteLine(line);
358
- - _resultsBlockWriter.WriteLine(line);
359
- + string line = $"{DateTime.UtcNow:O} {message}";
360
- + await _pageWriter.WriteLineAsync(line);
361
- + await _resultsBlockWriter.WriteLineAsync(line);
362
-
363
- _totalLines++;
364
- - if (line.IndexOf('\n') != -1)
365
- + if (line.Contains('\n'))
366
- {
367
- - foreach (char c in line)
368
- - {
369
- - if (c == '\n')
370
- - {
371
- - _totalLines++;
372
- - }
373
- - }
374
- + _totalLines += line.Split('\n').Length - 1;
375
- }
376
-
377
- - var bytes = System.Text.Encoding.UTF8.GetByteCount(line);
378
- + int bytes = Encoding.UTF8.GetByteCount(line);
379
- _byteCount += bytes;
380
- _blockByteCount += bytes;
381
- +
382
- if (_byteCount >= PageSize)
383
- {
384
- - NewPage();
385
- + await NewPageAsync();
386
- }
387
-
388
- if (_blockByteCount >= BlockSize)
389
- {
390
- - NewBlock();
391
- + await NewBlockAsync();
392
- }
393
- -
394
- }
395
-
396
- - public void End()
397
- + public async Task EndAsync()
398
- {
399
- - EndPage();
400
- - EndBlock(true);
401
- + await EndPageAsync();
402
- + await EndBlockAsync(true);
403
- }
404
-
405
- - private void NewPage()
406
- + private async Task NewPageAsync()
407
- {
408
- - EndPage();
409
- + await EndPageAsync();
318
+ @@ -125,8 +127,9 @@ namespace GitHub.Runner.Common
319
+ EndPage();
410
320
_byteCount = 0;
411
321
_dataFileName = Path.Combine(_pagesFolder, $"{_timelineId}_{_timelineRecordId}_{++_pageCount}.log");
412
322
- _pageData = new FileStream(_dataFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
@@ -416,29 +326,9 @@ index 9200ca59..6fa0decc 100644
416
326
+ _pageWriter = new StreamWriter(bufferedStream, Encoding.UTF8);
417
327
}
418
328
419
- - private void EndPage()
420
- + private async Task EndPageAsync()
421
- {
422
- if (_pageWriter != null)
423
- {
424
- - _pageWriter.Flush();
425
- - _pageData.Flush();
426
- - //The StreamWriter object calls Dispose() on the provided Stream object when StreamWriter.Dispose is called.
427
- + await _pageWriter.FlushAsync();
428
- + await _pageData.FlushAsync();
429
- _pageWriter.Dispose();
430
- _pageWriter = null;
431
- _pageData = null;
432
- - _jobServerQueue.QueueFileUpload(_timelineId, _timelineRecordId, "DistributedTask.Core.Log", "CustomToolLog", _dataFileName, true);
433
- + await _jobServerQueue.QueueFileUpload(_timelineId, _timelineRecordId, "DistributedTask.Core.Log", "CustomToolLog", _dataFileName, true);
434
- }
435
- }
436
-
437
- - private void NewBlock()
438
- + private async Task NewBlockAsync()
439
- {
440
- - EndBlock(false);
441
- + await EndBlockAsync(false);
329
+ private void EndPage()
330
+ @@ -148,8 +151,9 @@ namespace GitHub.Runner.Common
331
+ EndBlock(false);
442
332
_blockByteCount = 0;
443
333
_resultsDataFileName = Path.Combine(_resultsBlockFolder, $"{_timelineId}_{_timelineRecordId}.{++_blockCount}");
444
334
- _resultsBlockData = new FileStream(_resultsDataFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
@@ -448,23 +338,7 @@ index 9200ca59..6fa0decc 100644
448
338
+ _resultsBlockWriter = new StreamWriter(bufferedStream, Encoding.UTF8);
449
339
}
450
340
451
- - private void EndBlock(bool finalize)
452
- + private async Task EndBlockAsync(bool finalize)
453
- {
454
- if (_resultsBlockWriter != null)
455
- {
456
- - _resultsBlockWriter.Flush();
457
- - _resultsBlockData.Flush();
458
- + await _resultsBlockWriter.FlushAsync();
459
- + await _resultsBlockData.FlushAsync();
460
- _resultsBlockWriter.Dispose();
461
- _resultsBlockWriter = null;
462
- _resultsBlockData = null;
463
- - _jobServerQueue.QueueResultsUpload(_timelineRecordId, "ResultsLog", _resultsDataFileName, "Results.Core.Log", deleteSource: true, finalize, firstBlock: _resultsDataFileName.EndsWith(".1"), totalLines: _totalLines);
464
- + await _jobServerQueue.QueueResultsUpload(_timelineRecordId, "ResultsLog", _resultsDataFileName, "Results.Core.Log", deleteSource: true, finalize, firstBlock: _resultsDataFileName.EndsWith(".1"), totalLines: _totalLines);
465
- }
466
- }
467
- }
341
+ private void EndBlock(bool finalize)
468
342
diff --git a/src/Runner.Common/Runner.Common.csproj b/src/Runner.Common/Runner.Common.csproj
469
343
index 6c463562..933385ed 100644
470
344
--- a/src/Runner.Common/Runner.Common.csproj
0 commit comments