-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileConsumerService.cs
More file actions
39 lines (33 loc) · 1.04 KB
/
FileConsumerService.cs
File metadata and controls
39 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileWatching
{
public class FileConsumerService : IFileConsumerService
{
ILogger<FileConsumerService> _logger;
public FileConsumerService(ILogger<FileConsumerService> logger)
{
_logger = logger;
}
public async Task ConsumeFile(string pathToFile)
{
if(!File.Exists(pathToFile))
return;
_logger.LogInformation($"Starting read of {pathToFile}");
using (StreamReader sr = File.OpenText(pathToFile))
{
string? s = null;
int counter = 1;
while ((s = await sr.ReadLineAsync()) != null)
{
_logger.LogInformation($"Reading Line {counter} of the file {pathToFile}");
counter++;
}
}
_logger.LogInformation($"Completed read of {pathToFile}");
}
}
}