35 lines
920 B
C#
35 lines
920 B
C#
using System.Text;
|
|
|
|
namespace InnovEnergy.App.SaliMax;
|
|
|
|
public class LogFileConcatenator
|
|
{
|
|
private readonly string _logDirectory;
|
|
|
|
public LogFileConcatenator(String logDirectory = "LogDirectory/")
|
|
{
|
|
_logDirectory = logDirectory;
|
|
}
|
|
|
|
public String ConcatenateFiles(int numberOfFiles)
|
|
{
|
|
var logFiles = Directory
|
|
.GetFiles(_logDirectory, "log_*.csv")
|
|
.OrderByDescending(file => file)
|
|
.Take(numberOfFiles)
|
|
.OrderBy(file => file)
|
|
.ToList();
|
|
|
|
var concatenatedContent = new StringBuilder();
|
|
|
|
foreach (var fileContent in logFiles.Select(File.ReadAllText))
|
|
{
|
|
concatenatedContent.AppendLine(fileContent);
|
|
//concatenatedContent.AppendLine(); // Append an empty line to separate the files // maybe we don't need this
|
|
}
|
|
|
|
return concatenatedContent.ToString();
|
|
}
|
|
}
|
|
|