5

I am wondering what is the best folder to use to store config files (ini, xml) and log files for a Windows service.

According to the special folders list on msdn, it seems that CommonApplicationData (= C:\ProgramData on Windows Vista/7/Server 2008 (R2)) is the best suited place :

CommonApplicationData = The directory that serves as a common repository for application-specific data that is used by all users.

Any other advice?

Otiel
  • 18,404
  • 16
  • 78
  • 126

3 Answers3

2

the .NET config file generated from Visual Studio, called myService.exe.config should be saved in the same location as the exe. and it's an XML not an ini file.

Log files can be saved in a folder like C:\Logs\ServiceName or anything else you like, we usually create a network share on such folder so we can check log files also from other machines without need to connect to the server where the Windows Service is running.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • I am not using the .NET config file but a custom `ini` file. Should I store it with the `exe` file as well? – Otiel Sep 23 '11 at 09:19
  • how do you read those ini? I think is better with the service yes, if you are doing .NET managed C# windows service use the .NET config file, easy to use... :) ini is old fashion... – Davide Piras Sep 23 '11 at 09:20
  • With a INI management class. Something like that: http://www.csharpfr.com/codesource.aspx?ID=46880 – Otiel Sep 23 '11 at 09:22
1

For logging, I think the Windows Event Log is the most suitable. If you use Enterprise Library it's pretty easy to set up :)

Edit: Also, I would agree that using CommonApplicationData for config files is a good choice.

  • 2
    not always suitable, actually if you have tons of log database or plain text files are better – Davide Piras Sep 23 '11 at 09:12
  • True, it depends on what you're logging. If the application is very verbose it might be better to use another log repository. – Christian Palmstierna Sep 23 '11 at 09:14
  • 1
    yep. We use Log4Net with SMTPAppender for major errors, RollingFileAppender for ALL logs, and database logs for a medium level. – Davide Piras Sep 23 '11 at 09:15
  • I didn't ask what solution I should use to create logs, but where to store log files ;) I am already using NLog to write in text files, Windows Event Log don't suit me. – Otiel Sep 23 '11 at 09:17
0

Without much answers, I am just resuming in the following what I think and heard/read it's best:

  • Configuration files (ini, xml) should be stored with the exe file of the service.

  • Logs: The more modular way is to use a third-party logger (such as log4net or NLog - this thread is interesting for comparison). The folder where you will store your log file doesn't really matter, as long as it meets your needs (the service should have the sufficient rights to write in the folder, think who need to access to the log file and from where).

Community
  • 1
  • 1
Otiel
  • 18,404
  • 16
  • 78
  • 126
  • How would you handle access rights with such approach? I think about installing .exe of my service to something like C:\Program Files, but it does not look too good to write data to its folder then... – ironic Apr 01 '13 at 09:41
  • 2
    @ironic: In contrary to my answer, what I find best now (after a couple years of use) is to store both configuration and log files under C:\ProgramData\YourServiceName. Don't have to worry about access rights then. – Otiel Apr 03 '13 at 11:25