Otiel
Otiel

Reputation: 18743

Best place to store config and log files for a Windows service

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?

Upvotes: 5

Views: 4701

Answers (3)

Otiel
Otiel

Reputation: 18743

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).

Upvotes: 0

Davide Piras
Davide Piras

Reputation: 44605

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.

Upvotes: 2

Christian Palmstierna
Christian Palmstierna

Reputation: 1132

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.

Upvotes: 1

Related Questions