C
C#3y ago
Jona4Play

❔ Write X amount of lines to file and then start overriding

Hey, I want to log the last 20000 outputs of my project to a log file. I get one string per output and want it to append it to the bottom of the log file until 20000 entries have been reached. From thereon it should replace whatever line BatchCount currently is. Sadly, I haven't been able to figure it out myself. (BatchLimit is 20000 currently) TYIA Code Sample from Main Method
for (BatchCount = 0; BatchCount < BatchLimit; BatchCount++)
{
var doc = Scraper.ScrapFromLink(url);

DBManager.PushDataToDB(doc);
var w = DocumentSerializable.Convert(doc);
string jsonString = JsonConvert.SerializeObject(w);
LogWriter.WriteLineToLog(jsonstring,BatchCounter);
}
Batch++;
for (BatchCount = 0; BatchCount < BatchLimit; BatchCount++)
{
var doc = Scraper.ScrapFromLink(url);

DBManager.PushDataToDB(doc);
var w = DocumentSerializable.Convert(doc);
string jsonString = JsonConvert.SerializeObject(w);
LogWriter.WriteLineToLog(jsonstring,BatchCounter);
}
Batch++;
And here what I have now for the LogWriter
public static void WriteLineToLog(string content, int i)
{
if(Linecount <= CoreHandler.BatchLimit)
{
File.AppendAllText(CoreHandler.fileName, content);
}
else
{


}
}
public static void WriteLineToLog(string content, int i)
{
if(Linecount <= CoreHandler.BatchLimit)
{
File.AppendAllText(CoreHandler.fileName, content);
}
else
{


}
}
1 Reply
Accord
Accord3y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server