I m developing an application that reads files from a remote server and copies it onto the local drive.
The code I m using to read and write the file is –
string saveTo1 = savePath + @"\" + filename[i];
byte[] buffer = new byte[32768];
using (Stream input = getResponse.GetResponseStream())
{
using (FileStream output = new FileStream(saveTo1, FileMode.OpenOrCreate))
{
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
output.Close();
}
}
How can I create a log file that keeps track of the details of file copy and also records if there is any error while copying the files?
Thanks in advance 🙂
You can log in different ways.
answered)
log4net. It’s very powerfull
and highly customizable.
Any way, I would shape the code in this way, where MyLogManager implement one of the previous solutions: