none
Writing performance counter list into .csv file using Windows service. RRS feed

  • Question

  • I am trying to write performance counter list to file in .csv format while handling the logic in OnStart(string[] args) method. My Service is starting and stopping properly but file is not created and writing.

    here is my code.

     protected override void OnStart(string[] args)
            {
                StreamWriter writer = new StreamWriter("D://file.csv");
                writer.WriteLine("Started");
                writer.Flush();
                writer.Dispose();
                writer.Close();
         	 }
    Please help...

    With best regards, Vinayak S Joshi

    Thursday, May 31, 2012 9:12 AM

Answers

  • Try writing to a folder you know you have permission to write.  Verify that you can create a file on the D drive.  Make sure yo uare getting to this code.  The code is good, something else is wrong.

    jdweng

    Thursday, May 31, 2012 11:48 AM

All replies

  • first you should use Close before dispoose.  You may not have permission to write to the folder you are using.   Your backslashes are wrong if you are using windows.  try this instead

    @"D:\file.csv"

    Yo are probably writing your data to the default folder in the D drive and not the root folder.  the file is probably someplace on the D drive and if you did a search you would find the file.  Tow foward slashes doesn't make any sense on windows and may be the cause of the problem

    protected override void OnStart(string[] args)
           
    {
               
    StreamWriter writer = new StreamWriter(@"D:\file.csv");
                writer
    .WriteLine("Started");
                writer
    .Flush();
                writer.Close();
                writer.Dispose();
         }


    jdweng

    Thursday, May 31, 2012 10:11 AM
  • Hi Joel,

    Thanks for rectifying my mistakes. Unfortunately unable to create .csv file even after making changes


    With best regards, Vinayak S Joshi

    Thursday, May 31, 2012 11:04 AM
  • Try writing to a folder you know you have permission to write.  Verify that you can create a file on the D drive.  Make sure yo uare getting to this code.  The code is good, something else is wrong.

    jdweng

    Thursday, May 31, 2012 11:48 AM