I am trying to write a Logfile Writer class in c#. I want to do following: I write my logs in the 1st Logfile, if it is over a certain size, it will write in the 2nd logfile. If the 2nd logfile is full, then delete the 1st one and write in that one again and so on.
I've got this so far:
public class LogfileBuilder
{
StreamWriter sW;
const string file1 = "EventLogging1.txt";
const string file2 = "EventLogging2.txt";
FileInfo fInfo;
public void writeLine(string write)
{
string usingFile;
fInfo = new FileInfo(file1);
long s1 = fInfo.Length;
if (s1 > 300)
{
fInfo = new FileInfo(file2);
long s2 = fInfo.Length;
if (s2 > 300)
{
File.Create(file1).Close();
usingFile = file1;
}
else
{
usingFile = file2;
}
}
else usingFile = file1;
using (sW = File.AppendText(usingFile))
{
sW.WriteLine(write);
}
}
}
can anyone help me complete it please?