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();
}
}