0

I have created a windows service and writing Running logs to "/Log/" folder, Where can I find this folder.

It is not in Program Files where I installed the service.

I created the folder as per the Kyle's anser in Folder to dump windows service log files.

CODE to Create Folder:

        _logFolderPath = "/Logs/";
        string fileNameAndPath = Path.Combine(_logFolderPath, fileName);
        var fileInfo = new FileInfo(fileNameAndPath + ".txt");
        //Check if txt file exits
        if (!fileInfo.Exists)
        {
            //check if its directory exits, if not create
            if (!fileInfo.Directory.Exists) fileInfo.Directory.Create();
            //create file
            FileStream fs = fileInfo.Create();
            fs.Close();
        }
Community
  • 1
  • 1
Imran Rizvi
  • 7,331
  • 11
  • 57
  • 101
  • Put the code here and we'll see – Eric Herlitz Sep 11 '12 at 07:59
  • As I know service by default starts in system32 folder, so try to look at system32/Log – Renatas M. Sep 11 '12 at 08:00
  • I'm not sure it is a good practice to write in the windows directory. I would suggest you to write either in a custom dedicated directory, or in the ProgramData folder (`Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "/My Service/Logs"`) – Steve B Sep 11 '12 at 08:03
  • @Trikks Code added , its very common code to create folder. – Imran Rizvi Sep 11 '12 at 08:04
  • 1
    A quick tip: you can use `Path.Combine(_logfolderPath, fileName)` to join paths, instead of your backslash management. – Steve B Sep 11 '12 at 08:04
  • @Reniuz its not there in System32 folder – Imran Rizvi Sep 11 '12 at 08:04
  • Do you step in if statement? Cant you debug and see fileInfo.Directory details? – Renatas M. Sep 11 '12 at 08:08
  • @Reniuz for debugging I am using console application , there it is working fine, but i don't know if i can debug after installing it in windows service. – Imran Rizvi Sep 11 '12 at 08:10
  • 1
    Yes you can you need just learn new thing - `Debug->Attach to process` :) Also as note it is not common code to create folder. `Assembly.GetExecutingAssembly().Location` - this is how you could get location of your service executable. – Renatas M. Sep 11 '12 at 08:16
  • A Windows-service has the capability to use the MS Event-Log. Perhaps you want to prefer that for Errors and Warnings? – TGlatzer Sep 11 '12 at 08:35

0 Answers0