difference between textwriter and streamwriter [Resolved]

Posted by Tobi under C# on 5/15/2013 | Points: 10 | Views : 3358 | Status : [Member] | Replies : 1
hi evrybody
after installing a windows service wrote in c# visualstudio 2010,this service has to write in a log his starting date and when the service stop it has to report the date to.
but my service write in the log only the first time and nothing else after.
i stop and restart the service but nothing.
i used a streamwriter and a textwriter but i dont find the difference in the documentation of c#
if someone could help me i will be gratefull
here is my code:
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
if (File.Exists(@"C:\temp\demarrage.txt"))
{
TextWriter file = new StreamWriter(@"C:\temp\demarrage.txt", true);
file.WriteLine("attention demarrage2 effectué à:" + DateTime.Now.ToString() + "\n");
file.Close();
}
else
{
TextWriter file = File.CreateText(@"C:\temp\demarrage.txt");
file.WriteLine("attention premier demarrage du service apres deploiement effectué à:" + DateTime.Now.ToString() +"\n");
file.Close();
}


}

protected override void OnStop()
{
TextWriter file = new StreamWriter(@"C:\temp\demarrage.txt",true);
file.WriteLine("attention arretttttt effectué à:" + DateTime.Now.ToString() + "\n");
file.Close();
}
}




Responses

Posted by: Raja_89 on: 5/15/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hai
Text Writer
Represents a writer that can write in sequence series of characters
This is Abstract

StreamWriter
Implements a textwriter for writing characters to a stream in a particular encoding





Tobi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response