how to create text file in window service
<p>I have an XML file </p>

<pre><code>&lt;config&gt;
&lt;ServiceName&gt;autorunquery&lt;/ServiceName&gt;
&lt;DBConnection&gt;
    &lt;server&gt;servername&lt;/server&gt;
    &lt;user&gt;xyz&lt;/user&gt;
    &lt;password&gt;klM#2bs&lt;/password&gt;
&lt;initialcatelog&gt;TEST&lt;/initialcatelog&gt;

&lt;/DBConnection&gt;
&lt;Log&gt;
    &lt;logfilename&gt;d:\testlogfile.txt&lt;/logfilename&gt;
&lt;/Log&gt;
&lt;Frequency&gt;
    &lt;value&gt;10&lt;/value&gt;
    &lt;unit&gt;minute&lt;/unit&gt;
&lt;/Frequency&gt;
&lt;CheckQuery&gt;select * from credit_debit1 where station='Corporate'&lt;/CheckQuery&gt;
&lt;Queries total="3"&gt;
    &lt;Query id="1"&gt;Update credit_debit1 set station='xxx' where id=2&lt;/Query&gt;
&lt;Query id="2"&gt;Update credit_debit1 set station='xxx' where id=4&lt;/Query&gt;
&lt;Query id="3"&gt;Update credit_debit1 set station='xxx' where id=9&lt;/Query&gt;

&lt;/Queries&gt;
&lt;/config&gt;




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Xml;

namespace Service1
{
    public partial class Service1 : ServiceBase
    {
        XmlTextReader reader = null;
        string path = null;
        FileStream fs = null;
        StreamWriter sw = null;
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            timer1.Enabled = true;
            timer1.Interval = 10000;
            timer1.Start();
            logfile("start service");


        }

        protected override void OnStop()
        {
            timer1.Enabled = false;
            timer1.Stop();
            logfile("stop service");

        }
        private void logfile(string content)
        {

            try
            {
                reader = new XmlTextReader("queryconfig.xml");//xml file name which is in current directory
                if (reader.ReadToFollowing("logfilename"))
                {
                    path = reader.ReadElementContentAsString();
                }
                fs = new FileStream(path, FileMode.Append, FileAccess.Write);
                sw = new StreamWriter(fs);
                sw.Write(content);
                sw.WriteLine(DateTime.Now.ToString());

            }
            catch (Exception ex)
            {
                sw.Write(ex.ToString());
                throw;
            }
            finally
            {
                if (reader != null)
                    reader.Close();
                if (sw != null)
                    sw.Close();
                if (fs != null)
                    fs.Close();
            }
        }

    }
}
</code></pre>

<p>My problem is that the file is not created.</p>
