33 lines
949 B
C#
33 lines
949 B
C#
using System.Text;
|
|
|
|
namespace InnovEnergy.App.SinexcelCommunication.DataLogging;
|
|
|
|
public class LogFileConcatenator
|
|
{
|
|
private readonly String _LogDirectory;
|
|
|
|
public LogFileConcatenator(String logDirectory = "JsonLogDirectory/")
|
|
{
|
|
_LogDirectory = logDirectory;
|
|
}
|
|
|
|
public String ConcatenateFiles(int numberOfFiles)
|
|
{
|
|
var logFiles = Directory
|
|
.GetFiles(_LogDirectory, "log_*.json")
|
|
.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();
|
|
}
|
|
} |